The following article describes how Salesforce developers can take advantage of the TaskRay clone method in their own code.
This method is focused on creating a clone of a single project (and its sub projects) in a transaction. Using this method in a loop or multiple times in a transaction would be equivalent to SOQL queries and DML statements in a loop.
If you are cloning multiple projects at once consider: Using the TaskRay Bulk Clone Apex Method in Your Own Code
If you would like to create a project consisting of dynamically chosen tasks at the time of clone consider: Using the TaskRay Project Stitcher Apex Method in Your Own Code
One of the great things about building on the Salesforce platform is the ability to extend other features of the platform. Following that philosophy, we have made our Clone Project method Global, so other developers can use it without rebuilding the wheel.
However, if you would like to learn more about the Project Clone and how it works, you can view the following articles:
TaskRay Project Clone Method
The Signature for this method is:
TASKRAY.trTaskBoardController.cloneProjectReturnID_v3(IdbaseProjectID, Map<String, Map<string, String>> projectInfo, Map<String,String> options);
- Id baseProjectId 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.
- Map<String, Map<String,String>> projectInfo This parameter is a map of TaskRay Project IDs relating to another map of override values for that Project. Valid override values for a project are 'newName', 'newStartDate', 'newEndDate'. The dates should be formatted in the current user's locale using something similar to:Date.today().format()
- Map <string,string> options The options parameter is a map of keys to values determining what features we will use in the clone operation.
Values for Options Map
- 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.
- A key of 'cloneChildrenProjects' can have a corresponding value of 'true' or 'false', this option will determine if children of the baseProjectId parameter are cloned.
- A key of 'depCloneBasedOnProjectStart' can have a corresponding value of 'true' or 'false', this option will determine if the task dates will clone relative to the project start. A key of 'depCloneBasedOnProjectEnd' can have a corresponding value of 'true' or 'false', this option will determine if the task dates will clone relative to the project end.
- A key of 'createLookupToRecordId' can have a corresponding value of 'true' or 'false', this option will initiate the process of associating the new project to a record in Salesforce.
- A key of 'recordIdForLookup' takes a Salesforce record Id as a value. If the option 'createLookupToRecordId' is 'true', the value of 'recordIdForLookup' will be associated with the new project, if the project has that record Id type as an available custom field.
//This is our top level project id Id baseProjectId = 'a0ja000000L7wRzAAJ'; //Project overrides Map<String,Map<String,String>> projectInfo = new Map<String,Map<String,String>>(); Map<String,String> projectOverrides = new Map<String,String>(); projectOverrides.put('newName','Cloned Top Level Project '+Date.today().format()); projectOverrides.put('newStartDate',Date.today().addDays(-2).format()); projectInfo.put(baseProjectId,projectOverrides); //Now override a subproject's information projectOverrides = new Map<String,String>(); projectOverrides.put('newName','Cloned Third Level Project '+Date.today().format()); //'a0ja000000L7wS9AAJ' is the id for our "Third Level Clone Template" project projectInfo.put('a0ja000000L7wS9AAJ',projectOverrides); //Clone operation options Map<String,String> options = new Map<String,String>(); options.put('cloneChildrenProjects','true'); options.put('assignInactiveToCurrent','true'); options.put('depCloneBasedOnProjectStart','true'); Id newBaseProjectId = TASKRAY.trTaskBoardController.cloneProjectReturnId_v3(baseProjectId, projectInfo, options); //Notice that the Project Clone method returns the Id of the new baseProjectId equivalent //The sky is the limit on what you can do after the projects are created by inserting your own //business logic, updating custom fields, link lookup relationships system.debug(newBaseProjectId);
- Project Records
- Task Records
- Checklist Item Records
- Team Members / Shares
- Chatter Topics
- Checklist Items for Tasks