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 projects at once in their own code. Usually you would be using this apex method when you are looking to create many projects in a single transaction. This method is very useful if you are looking to create many clones at once and may have hit governor limits using other methods.
If you would like to learn more about Project Cloning and how it works, you can view the following articles:
TaskRay Clone Projects Method
The Signature for this method is:
Map<String,Id> TASKRAY.trTaskBoardController.cloneProjectsReturnIds(Map<String,Map<String,Object>> projectInfo, Map<String,Object> cloneOptions);
Parameters
- Map<String,Map<String,Object>> projectInfo This is simply the ID of the TaskRay Project Record you would like to clone. If you are cloning a hierarchy of projects, this is the top level project for the clone.
- Project Info Entry Shape
{ myUniqueReturnMappingId1:{ templateProjectId: (Id), newName: (String), newStartDate: (Date), newEndDate: (Date), contextRecordId: (Id), depCloneBasedOnProjectStart: (Boolean), depCloneBasedOnProjectEnd: (Boolean), depCloneBasedOnDrivingMilestone (Boolean), drivingMilestoneId: (Id), drivingMilestoneDate: (Date) }, myUniqueReturnMappingId2:{...},... }
- Usage Considerations:
- contextRecordId is the Id of any SObject. After the clone is complete the apex method will populate any lookups of the same SObject type with the contextRecordId
- Only one of depCloneBasedOnProjectStart, depCloneBasedOnProjectEnd, depCloneBasedOnDrivingMilestone should be set to true
- drivingMilestoneId and drivingMilestoneDate are only required if depCloneBasedOnDrivingMilestone is set to tru
- The myUniqueReturnMappingId1-n must be unique strings. When the method returns a Map<String,Id> this string key will be available in the returned map and it's corresponding value will be the newly created project id. This will allow you to perform other operations on the project after it has been cloned.
Note: DO NOT use a - character in these unique strings. It will cause a conflict in the internal bulk clone method.
- Project Info Entry Shape
- Map <String,String> cloneOptions The options parameter is a map of keys to values determining what features we will use in the clone operation.
- A key of 'assignInactiveToCurrent' can have a corresponding value of 'true' or 'false', this option will assign tasks which are owned by an inactive user to the current user.
Example Usage
First, if you have not already, you should create a few template projects in TaskRay (create a Template Project ). We will use these templates for our cloning. In our example we have two existing templates with these ids: a02U000000aKi33IAC a02U000000aKijoIAC.
Apex Code
Map<String,Map<String,Object>> projectInfo = new Map<String,Map<String,Object>>(); Map<String,Object> project1Details = new Map<String,Object>(); project1Details.put('templateProjectId','a02U000000aKi33IAC'); project1Details.put('newName','Fulfill sprocket'); project1Details.put('depCloneBasedOnProjectStart', true); project1Details.put('newStartDate',Date.parse('9/1/2018')); projectInfo.put('sprocket',project1Details); Map<String,Object> project2Details = new Map<String,Object>(); project2Details.put('templateProjectId','a02U000000aKijoIAC'); project2Details.put('newName','Fulfill custom widget'); project2Details.put('depCloneBasedOnProjectStart', true); project2Details.put('newStartDate',Date.parse('9/1/2018')); projectInfo.put('custwidget',project2Details); Map<String,Object> cloneOptions = new Map<String,Object>(); cloneOptions.put('assignInactiveToCurrent', true); Map<String,Id> retInfo = TASKRAY.trTaskBoardController.cloneProjectsReturnIds(projectInfo, cloneOptions); system.debug(retInfo);
Summary
So, to recap, we were able to use the TaskRay Bulk Clone Apex Method to clone multiple projects at once. This method bulkifies all DML actions and can support many projects being created at once.
Things cloned in this method:
- Project Records
- Task Records
- Checklist Item Records
- Team Members / Shares
- Chatter Topics
- Checklist Items for Tasks
Things not cloned in this method:
- Chatter