ClosePlan Opportunity Auto-deployment
By default, Users manually deploy ClosePlans to Opportunities by clicking on the Create button. If only one Template is available, it is automatically selected for deployment. If more than one template is available, the User will be prompted to choose which Template to deploy.
ClosePlans may also be deployed automatically based on Opportunity creation or other criteria. ClosePlan provides several ways to achieve this.
Template Selection
In order to use automated deployment, the Template which will be used for deployment must be specified. Choose the specific version and version IDs directly from the ClosePlan Admin Template detail, or implement logic to retrieve the latest version for a specific Template based on specific Opportunity data.
ClosePlan in-template filter configuration works only from the UI during manual deployment so you must decide which template to use for which Opportunity. You can replicate the original filtering, but you can also achieve much more complex logic if needed.
If your organization uses Opportunity Record Types with multiple Sales Processes, and ClosePlan Templates have Staging functionality enabled for Playbooks, remember that the destination Opportunities must use the same Sales Process as defined in the Template. Otherwise, the deployment will be canceled.
Opportunity Selection
In order to use automated deployment, you will need to specify to which Opportunities ClosePlan should be deployed.
This is usually achieved with Opportunity Triggers, using records that are being currently updated in conjunction with any additional logic.
You may also query any Opportunities using SOQL with any conditions you like.
If you try to Deploy a ClosePlan to Opportunity that already has a ClosePlan, the deployment will be canceled. You can always determine if a ClosePlan exists by checking TSPC__HasDeal__c field on the Opportunity. This field will be null if no ClosePlan exists.
Deployment using APEX
There are two ways to deploy for APEX, synchronous and asynchronous.
Synchronous
The synchronous approach supports a single Opportunity record deployment at a time only. Use this approach if you expect that the user should see ClosePlan in place immediately after the transaction completes.
Asynchronous
For multiple Opportunity deployment, use an asynchronous approach or switch between both synchronous and asynchronous based on data-set size. The asynchronous approach will not slow running users.
The logic related to when the deployment should occur is solely up to you, but usually it is triggered after Opportunity creation, Stage change, or any other plausible criteria.
Asynchronous Deployment using Batch job
⊕ Ability to deploy multiple records
⊕ Async run won’t slow down users
⊖ It might take few seconds until ClosePlan appears in the UI
⊕ Can be invoked from Triggers or any Apex class
// Provide Template ID
// Note: You can use static template ID or retrieve the latest version for particular Template
Id templateId = 'a684R000000H7HOQA0';
// Provide set of Opportunity Ids, which should be deployed
Set<Id> oppIds = new Set<Id>{'0060Y00000B8XcX'};
// Create deploy job and execute
TSPC.CPSJob_DealDeploy job = new TSPC.CPSJob_DealDeploy(oppIds, templateId);
Id jobId = DataBase.executeBatch(job, 5); // Max 10 - Tweak depending on template complexity.
Synchronous Deployment
⊖ Ability to deploy only to single Opportunity
⊖ Might slow down users
⊕ Available immediately after transaction completes
⊕ Can be invoked from Triggers or any Apex class
// Provide Template ID
// Note: You can use static template ID or retrieve the latest version for particular Template
Id templateId = 'a684R000000H7HOQA0';
// Provide Opportunity ID
Id opportunityId = '0060Y00000B8XcX';
// Invoke deployment
TSPC.CPSJob_DealDeploy.deployDeal(opportunityId, templateId, null);
Deployment using Flows
The following example shows how to create a Salesforce Flow to assign a ClosePlan Template automatically whenever a new Opportunity is created.
Setup > Process Automation > Flows
Click New Flow
Select Record-Triggered Flow
Click Create
For Select Object, select: Opportunity
For Configure Trigger, select: A record is created
For Set Entry Conditions, define any conditions or none. In this example we will not define any conditions.
For Optimize the Flow for, select: Actions and Related Records
Click Done
Click the plus sign in the circle to Add Element
Select Action
In the New Action modal window under Action, search for and enter: ClosePlan: Deploy Opportunity Template
In the New Action modal, for Label: enter Deploy ClosePlan Template. The API Name will autofill.
Under Set input Values, find $Record Opportunity and click to enter, then click outside of the box. The value should read: {!$Record} -
Note: The value may sometimes read: {!$Record.} - the period after ‘Record’ must be deleted.
If there is only one active ClosePlan Template, leave the ‘Don’t Include’ toggle switch off. The Flow will then deploy the only Active Template.
If there is more than one Template Active, and you want a specific Template deployed, go to:
ClosePlan Admin tab > Templates > Copy the Template ID.
You will then activate the toggle switch and paste the Template ID in the field.Click Done
Click Save
For Flow Label enter: Deploy ClosePlan Template. The Flow API Name will autofill.
Click Save
Click Activate to activate the Flow