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
- List<Map<String,Object>> taskInfo This is the configuration for each task which you will be cloning.
- Task Info Entry Shape
{ templateTaskId: (Id), taskName: (String), taskStartDate: (Date), taskEndDate: (Date), projectId: (Id), ownerId: (Id) }, { templateTaskId: (Id),... }
- Task Info Entry Shape
- 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 Project ). We will use these templates for our cloning. In our example we have two existing templates tasks with these ids: a02U000000aKi33IAC a02U000000aKijoIAC.
Apex Code
List<Map<String,Object>> taskInfo = new List<Map<String,Object>>(); Map<String,Object> task1Info = new Map<String,Object>(); task1Info.put('templateTaskId',(Object)'a01630000088W8iAAE'); 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)'a01630000088W6rAAE'); 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