Use the TaskRay Bulk Clone Apex Method in Your Own Code

This feature is available on the following TaskRay 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

  1. 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.
    Note: For cloning templates, you will need to utilize the TaskRay ID Resolver to convert the template Addressable ID to a Salesforce ID. This will ensure your code always clones the active version of the template.
      1. 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:{...},...
          }
      2. Usage Considerations:
        1. 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
        2. Only one of depCloneBasedOnProjectStart, depCloneBasedOnProjectEnd, depCloneBasedOnDrivingMilestone should be set to true
        3. drivingMilestoneId and drivingMilestoneDate are only required if depCloneBasedOnDrivingMilestone is set to tru
        4. 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.
  2. Map <String,String> cloneOptions The options parameter is a map of keys to values determining what features we will use in the clone operation.
    1. 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 templates in TaskRay (create a Template). We will use these templates for our cloning. In our example we have two existing templates with these ids: a02U000000aKi33IAC a02U000000aKijoIAC.
Note: The IDs above are the output from the TaskRay ID Resolver. You will need to utilize the template Addressable IDs with the Resolver to ensure your clone operation always uses the active versions of your templates.
 

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

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request