Use the TaskRay Task Clone Apex Method in Your Own Code

This feature is available to the following product editions
  • Starter
  • Standard
  • Premium

The following article describes how Salesforce developers can take advantage of global Apex methods to clone many tasks at once in their own code. Usually you would be using this apex method when you are looking to create many tasks in a single transaction. This method is very useful if you are looking to create many clones of a task at once and may have hit governor limits using other methods.

If you would like to learn more about Task Cloning and how it works, you can view the following articles:

 

TaskRay Clone Tasks Method

The Signature for this method is:

List<Project_Task__c> TASKRAY.trTaskBoardController.cloneTasksReturnTasks(List<Map<String,Object>> taskInfo, Map<String,Object> options)

 

Parameters

  1. List<Map<String,Object>> taskInfo This is the configuration for each task which you will be cloning.
      1. Task Info Entry Shape
          {
              templateTaskId: (Id),
              taskName: (String),
              taskStartDate: (Date),
              taskEndDate: (Date),
              projectId: (Id),
              ownerId: (Id)
          },
          {
              templateTaskId: (Id),...
          }
  2. Map <String,String> cloneOptions The options map is reserved for future use. Right now just pass an empty Map<String,String>
 

Example Usage 

First, if you have not already, you should create a few template tasks in TaskRay (create a Template). We will use this template, and related Tasks, for our cloning. In our example we have an existing template with two existing templates tasks with these addressable ids: ‘PT_6NKvQHfRh.TK_hjmoQmt1P’, ‘PT_6NKvQHfRh.TK_ByjABCZxD’.
We also have an existing Project we wish to clone these Tasks into, with a Salesforce Id of 'a0263000002uFYkAAM'.
 

Apex Code

//This is our collection of Task Addressable Ids for which to get Salesforce Ids
List<String>addressableIds = new List<String>{‘PT_6NKvQHfRh.TK_hjmoQmt1P’, ‘PT_6NKvQHfRh.TK_ByjABCZxD’};

//Here we will return a map of the original Addressable Id value with the corresponding Salesforce Id for the active version of the related template Project Tasks to be cloned
//This allows you to retrieve Salesforce Ids for more than one Addressable Id at a time, to avoid potentially hitting governor limits for SOQL
//You can use this data however you like to reference the Salesforce Id as needed
Map<String, Id> mapOfAddressableToSalesforceIds = TASKRAY.trCustomerActions.convertAddressableIds(addressableIds);

Id templateTaskId1 = mapOfAddressableToSalesforceIds.get(‘PT_6NKvQHfRh.TK_hjmoQmt1P’);

Id templateTaskId2 = mapOfAddressableToSalesforceIds.get(‘PT_6NKvQHfRh.TK_ByjABCZxD’);

List<Map<String,Object>> taskInfo = new List<Map<String,Object>>();

Map<String,Object> task1Info = new Map<String,Object>();
task1Info.put('templateTaskId',(Object),templateTaskId1);
task1Info.put('taskName',(Object)'New Template 1 Name');
task1Info.put('taskStartDate',(Object)Date.today());
task1Info.put('taskEndDate',(Object)Date.today());
task1Info.put('projectId',(Object)'a0263000002uFYkAAM');
task1Info.put('ownerId',(Object)UserInfo.getUserId());
taskInfo.add(task1Info);

Map<String,Object> task2Info = new Map<String,Object>();
task2Info.put('templateTaskId',(Object),templateTaskId2);
task2Info.put('taskName',(Object)'New Template 2 Name');
task2Info.put('taskStartDate',(Object)Date.today());
task2Info.put('taskEndDate',(Object)Date.today());
task2Info.put('projectId',(Object)'a0263000002uFYkAAM');
task2Info.put('ownerId',(Object)UserInfo.getUserId());
taskInfo.add(task2Info);

Map<String,String> cloneOptions = new Map<String,String>();

List newlyClonedTasks = TASKRAY.trTaskBoardController.cloneTasksReturnTasks(taskInfo, cloneOptions);
system.debug(LoggingLevel.ERROR, newlyClonedTasks);

 

Summary

So, to recap, we were able to use the TaskRay Task Clone Apex Method to clone multiple tasks at once. This method bulkifies all DML actions and can support many tasks being created at once.
 
Things cloned in this method:  
  • Task Records 
  • Checklist Groups
  • Checklist Item Records 
  • Chatter Topics 
 
Things not cloned in this method:  
  • Chatter

Was this article helpful?

1 out of 3 found this helpful

Have more questions? Submit a request