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 construct a new project containing a dynamic set of Task Groups or add a dynamic set of Task Groups to a existing project. This Apex method is invocable and executable via Flow and the Salesforce REST API as well.
If you would like to learn more about Project Stitching and how it works, you can view the following articles:
TaskRay Clone Projects Method
The Signature for this method is:
List<Id> TASKRAY.trStitchProjectsFlow.stitchProject(List<TASKRAY.trStitchProjectsFlow.Request> requests);
Parameters
-
List<TASKRAY.trStitchProjectsFlow.Request> requests This input parameter is a list of classes which define how to create/update a project with a dynamic set of template task groups.
-
TASKRAY.trStitchProjectsFlow.Request class definition
global class Request {
@InvocableVariable(label='New Project?' required=true)
global Boolean createNewProject;
@InvocableVariable(label='Existing Project Id (only if New Project? is false)' required=false)
global Id existingProjectId;
@InvocableVariable(
label='New Project Date Target (only if New Project? is true)'
required=false
)
global Date projectDateTarget;
@InvocableVariable(label='New Project Name (only if New Project? is true)' required=false)
global String projectName;
@InvocableVariable(
label='New Project Schedule Mode (only if New Project? is true "Start", "End", or a Milestone Id)'
required=false
)
global String projectScheduleMode;
@InvocableVariable(
label='New Project Template Addressable Id (only if New Project? is true)'
required=false
)
global string projectTemplateAddressableId;
@InvocableVariable(
label='New Project Template Salesforce Id (only if New Project? is true)'
required=false
)
global Id projectTemplateId;
@InvocableVariable(label='Source Object Id (populates lookup fields on project)' required=false)
global Id sourceRecordId;
@InvocableVariable(label='Task Group Addressable Id List' required=false)
global List<string> taskGroupAddressableIds;
@InvocableVariable(label='Task Group Salesforce Id List' required=false)
global List<Id> taskGroupIds;
@InvocableVariable(
label='Task Group Schedule Mode List ("Start", "End", or a Milestone Id)'
required=false
)
global List<String> taskGroupScheduleModes;
@InvocableVariable(label='Task Group Target Date List' required=false)
global List<Date> taskGroupTargetDates;
}
-
TASKRAY.trStitchProjectsFlow.Request class definition
Return Value
- List<Id> these ids correspond to the new created or updated Project Ids for each instance of the Request class
Example Usage
First, if you have not already, you should create a template as well as some template task groups (create a Template Project). We will use these templates for our cloning. In our example we will be creating a new project consisting of a few task groups. The base template will have no task groups within it, and the template task groups will reside in another template.
Note: For all template ID inputs, you will need to utilize the TaskRay ID Resolver to convert the template Addressable IDs to a Salesforce IDs. This will ensure your code always clones the active version of the template project/task groups.
Apex Code
//Opportunity to relate the new project to Id opportunityId = '0060P00000gQF98'; //Base template project Id Id templateProjectId = 'a020P00000hVA5OQAW'; //Template Task Group Ids for products //Keep in mind you could also look these up from opportunity products or something similar Id sprocketFulfillmentTaskGroupTemplateId = 'a0Y0P00000EO9Wn'; Id widgetFulfillmentTaskGroupTemplateId = 'a0Y0P00000EOwmJ'; List templateTaskGroupIds = new List(); templateTaskGroupIds.add(sprocketFulfillmentTaskGroupTemplateId); templateTaskGroupIds.add(widgetFulfillmentTaskGroupTemplateId); List requests = new List(); //Configure the request class TASKRAY.trStitchProjectFlow.Request req = new TASKRAY.trStitchProjectFlow.Request(); req.createNewProject = true; req.projectTemplateId = templateProjectId; req.projectName = 'Acme Fulfillment Project'; req.projectScheduleMode = 'Start'; req.sourceRecordId = opportunityId; req.projectDateTarget = Date.today(); req.taskGroupIds = new List(); req.taskGroupScheduleModes = new List(); req.taskGroupTargetDates = new List(); for(Id templateTaskGroupId : templateTaskGroupIds){ req.taskGroupIds.add(templateTaskGroupId); req.taskGroupScheduleModes.add('Start'); req.taskGroupTargetDates.add(Date.today()); } requests.add(req); //Run the clone List newlyCreatedProjectIds = TASKRAY.trStitchProjectFlow.stitchProject(requests); //Get the newly created project id system.debug(newlyCreatedProjectIds);
Summary
So, to recap, we were able to use the TaskRay Project Stitcher Apex Method to create a project with dynamic task groups "stitched" together to make the exact project your business needs. This method bulkifies all DML actions and can support many task groups and projects being created at once.
Things cloned in this method:
- Project Records (optionally)
- Task Records
- Checklist Item Records
- Team Members / Shares
- Chatter Topics
- Checklist Items for Tasks
Things not cloned in this method:
- Chatter