Automatically create tasks via custom Flow, Process Builder, or Apex Trigger
Prerequisites:
In the checklist you usually want to use the following settings:
- Only for Object - enter the Object, e.g. Lead, Opportunity, Account, custom object, ...
- Make sure that "Manual only" is de-selected and "Apply only once" is checked
Create a new Flow
- Record-Triggered Flow
Configure Start
- Select the Object (e.g. Account)
- Select: A record is created or updated
- Entry Condition (same as in the checklist)
- Select: Actions and Related Records
Flow Builder
Add New Action
The different options:
- Add Checklist Tasks (all)
- check all checklists that apply (Only Object, Only if Valid) and NOT manual only and add checklist tasks for potentially multiple checklists
- Add Checklist Tasks (by Name)
- select the name or code of the checklist and the record id. Note that the Only Object and Only if Valid still need to be valid for the record (i.e. it will not just add the tasks)
- Add Checklist Tasks (first)
- check all checklists and use the first one (based on ordering by code) which applies (Only Object, Only if Valid) and NOT manual only
For the Object Id, enter {!$Record.Id}
Example:
Save, test, and activate the flow
Create a new Process in Process Builder (alternative)
- Add Object
- select any criteria suitable for the situation, e.g. when a record is created - Add Criteria
- enter conditions or formula - or just execute - Add Immediate (or scheduled) Action
- Action Type: Apex
- Apex Class: Add Checklist Tasks (first) -- or Add Checklist Tasks (all)
- Set Apex Variables
-- Field: ids
-- Type: Field Reference
-- Value: The Id of the record
Then, activate the Process.
The Apex processes
- Add Checklist Tasks (first)
- Add Checklist Tasks (all)
add the checklists where the "Only if valid" criteria apply. For starting just one (the first), make sure that the code of the checklist is alphabetically the first option.
In Process Builder (or Flow), you can create sophisticated criteria, so the "Only if valid" could be skipped.
For this, use the Apes Process: Add Checklist Tasks (by Name). Here no restrictions apply, but also no check, e.g. that the entity you started the process is "Only for Object" or that the entity complied "Only if valid". It is assumed, that you check that in the decisions before starting the Apex action.
Apex Details
We provide the following APEX classes/methods which you can invoke via Process Builder or call from a custom class or trigger. The general steps are:
- Find the checklists for the object type of the record (e.g. Account)
- ensure that the checklist matches the Only for Object (if defined) and the Only if valid conditions (if defined)
- the sequence is based on the checklist Code
- Create Tasks from the Checklist Items
- Assign to the Owner of the Task to the owner of the record
-- or if defined in the Checklist Item, the Assigned User -- or the Dynamically Assigned User - Set the Due Date of the Task based on today's date and the Date Offset Days (and Use Workdays) for tasks without prerequisites
- Set the Status of the Task to Not Started or Waiting on someone else (for tasks with prerequisites)
- Assign to the Owner of the Task to the owner of the record
Create Tasks only for the first matching checklist:
global class acheck.CheckListCreate { /** * Process Builder Interface * @param ids list of record ids - select Type: Field Reference and the Value: id */ @InvocableMethod( label='Add Checklist Tasks (first)' description='Creates Tasks from the Items of the highest priority matching CheckList') global static void create(List<String> ids) {} /** * Add CheckList Tasks of first matching Checklist for record with Id * @param whatId the id of the target record * @return list of the saved tasks or null if no checklist found */ global static List<Task> forId(Id whatId) {} }
Create Tasks only for all matching checklists:
global class acheck.CheckListCreateAll { /** * Process Builder Interface * @param ids list of record ids - select Type: Field Reference and the Value: id */ @InvocableMethod( label='Add Checklist Tasks (all)' description='Creates Tasks from the Items of all matching CheckLists') global static void createAll(List<String> ids) {} /** * Add all CheckList Tasks for record with Id * @param whatId the id of the target record * @return list of the saved tasks or null if no checklist found */ global static List<Task> forIdAll(Id whatId) {} }