Note: 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='Source Object Id (populates lookup fields on project)' required=false) global Id sourceRecordId; @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 Date Target (only if New Project? is true)' required=false) global Date projectDateTarget; @InvocableVariable(label='New Project Template Id (only if New Project? is true)' required=false) global Id projectTemplateId; @InvocableVariable(label='Task Group Id List' required=true) global List taskGroupIds; @InvocableVariable(label='Task Group Schedule Mode List ("Start", "End", or a Milestone Id)' required=false) global List taskGroupScheduleModes; @InvocableVariable(label='Task Group Target Date List' required=false) global List 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 project 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 project template will have no task groups within it, and the template task groups will reside in another template project container.
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