Executing an Automation Template
- Adding an Automation Template to a Connection Behavior
- Executing a Template From An Automation Template Record
- Executing an Automation Template from a Deployment Step
- Executing an Automation Template Function
- Executing an Automation Template from Apex
- Executing an Automation Template from a Salesforce Flow
In the Automation Templates article, you have learned what an automation template is and how you can build one. In this article, you will learn how you can execute a template.
Copado enables you to execute a template from multiple places, not only as part of your quality process with Copado Continuous Delivery but also in a standalone deployment or as part of a Salesforce flow.
Let’s take a look at the different options you can use to execute a template.
Adding an Automation Template to a Connection Behavior
If you are working with Copado Continuous Delivery, you may want to create an automation template for a certain group of steps to be executed whenever you deploy to a particular environment.
To do this, you just need to navigate to a connection behavior and add a new automation of type Automation from the Automations tab:
As with other automations, you can select the metadata group that will trigger the execution of the template, a template (if you don’t have one already, you can click on New Deployment within the Automation Template lookup field and build one) and the execution sequence, which can be before or after the deployment:
Executing a Template From An Automation Template Record
You can execute an automation template on-demand, so you can test and run your automations anytime. To do so, go to an existing automation template and click on Execute Template. If needed, you can select a source credential and a destination credential:
You can decide to execute the deployment straightaway by checking the Execute Immediately checkbox:
If not, the deployment will be created, but for it to be executed, you will have to click on Deploy:
A Copado Result record is automatically created once the template is executed.
To be able to execute a template, you need either of these two options:
- The Flow User checkbox selected for your user.
- The Run Flows permission at permission set or profile level.
Executing an Automation Template from a Deployment Step
If you are working with a standalone org-to-org deployment, you can add an Automation Template deployment step. Just select an Advanced (multi-step) deployment, add an Automation step and select a template from the Automation lookup field:
Once the step is executed, a child Deployment record is created with the steps in the automation template following the naming convention Execution of [Template Name]. A Result record is also automatically created with a lookup field to the child deployment.
Executing an Automation Template Function
If you are building an automation with a Salesforce flow or Apex that needs to execute an automation template, you can leverage a Copado Apex action.
This Apex action requires the following parameters:
- Automation Template record id (required)
- Data type: string
- Execute Immediately (optional)
- Data type: boolean
- By default, this option equals true. If you wish to execute the automation steps at another point in time, enter false.
- Source Credential (optional)
- Data type: string
- By default, this option equals the executing user’s Copado Credential record id. This is because the automation steps may not need a source or destination org since they are executing non-Salesforce org-dependent automations. If your automation steps require a different source credential, enter the Credential record id.
- Destination Credential (optional)
- Data type: string
- By default, this option equals the executing user’s Copado Credential record id. This is because the automation steps may not need a source or destination org since it is executing non-Salesforce org-dependent automations. If your automation steps require a different destination credential, enter the Credential record id.
This Apex action returns a result id.
Executing an Automation Template from Apex
List<copado.ConvertAutomationToDeployment.InvocableVariables> variables = new List<copado.ConvertAutomationToDeployment.InvocableVariables>();
copado.ConvertAutomationToDeployment.InvocableVariables firstSet = new
firstSet.automationTemplateId = 'a0S3t00000K7OLlEAN';
firstSet.execute = true;
firstSet.sourceCredentialId = 'a0m3t000009N0xlAAC';
firstSet.targetCredentialId = 'a0m3t000009N0xlAAC';
If you would like to test this script, copy and paste it in the Apex anonymous window of the Developer Console and specify the record Id of an automation template. After executing it, go to the Results tab. You will find a new record with a lookup to the deployment that contains the automation steps with the name Execution of [Automation Template Name].
Executing an Automation Template from a Salesforce Flow
Automation templates can also be executed as part of a Salesforce flow by means of the Execute Automation Template Apex action. All you need to do is drag and drop an Action item into your Salesforce flow and select Execute Automation Template. Enter the required parameters and click on Done.