Automation Templates

Updated 1 week ago by Copado Solutions

Introduction

An automation template is a reusable template that contains a list of steps that can be executed in the future. Let’s say you want to execute a data backup whenever you deploy a data template, you can configure an automation template to run a data backup and reuse it every time you do a data migration.

An automation template can be executed as part of an Apex class and from an external source using a Copado webhook, but also as part of a connection behavior if you are working with Copado Continuous Delivery. You can configure the template directly in a connection behavior or in a deployment step.

Now, what kind of actions or steps can be included in an automation template? Currently, three steps are supported:

  • Apex
  • Salesforce Flow
  • External CI

Now that you have an idea of what an automation template is, let’s go on to describe the different sections and fields you can find in a template and see how it actually looks like.

Tabs and Fields

An automation template contains three main tabs, Details, Steps and Execution History.

In the Details tab you can provide a name for your template and a description. The Active checkbox lets users know the template is ready to be used. Once you have finished configuring your template and are happy with the changes, you can select this checkbox:

The Steps tab is where you can configure the different steps you want to execute as part of the automation template. Give your step a name and select a step type from the drop-down menu:

A screen to configure the selected step will be displayed. In the example below, you can see the Salesforce Flow step configuration screen:

You can add as many steps as you need, there are no limitations.

Finally, in the Execution History tab you will find a record for each time the template has been executed, and you can navigate to the deployment that triggered the execution:

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 will be created with the steps in the automation template following the naming convention Execution of [Template Name]. A Result record will also be automatically created with a lookup field to the child deployment.

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 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 do so leveraging a Copado Apex action. 

This Apex action requires the following parameters:

  1. Automation Template record id (required)
    1. Data type: string
  2. Execute Immediately (optional)
    1. Data type: boolean
    2. By default, this option equals true. If you wish to execute the automation steps in another point in time, enter false.
  3. Source Credential (optional)
    1. Data type: string
    2. By default, this option equals the executing user’s Copado Org 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 Org Credential record id.
  4. Destination Credential (optional)
    1. Data type: string
    2. By default, this option equals the executing user’s Copado Org 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 Org 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
copado.ConvertAutomationToDeployment.InvocableVariables();
firstSet.automationTemplateId = 'a0S3t00000K7OLlEAN';
firstSet.execute = true;
firstSet.sourceCredentialId = 'a0m3t000009N0xlAAC';
firstSet.targetCredentialId = 'a0m3t000009N0xlAAC';
variables.add(firstSet);

copado.ConvertAutomationToDeployment.execute(variables);

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 and 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.


How did we do?