Automatically create tasks via custom Triggers or Process Builder.


Prerequisites:

The checklist you usually want to use 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 

Checklist Restrictions


Create a new Process in Process Builder

  • 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


Process Builder Add Action

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.

Add Checklist Tasks (by Name) 

  


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)


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) {}
}