Apex Invocable Methods

Updated 9 months ago by Copado Solutions

Copado provides a wide range of Apex invocable methods that allow you to easily execute different Copado jobs as part of your flow or process builder, or from an Apex class, from taking a Git snapshot to executing an automation template.

Available Apex Methods

There are many different jobs that can be automated with Copado. Here you can find the list of all available Apex methods:

  • Calculate Org Differences (CalculateOrgDifferences)
  • Calculate Snapshot Differences (CalculateSnapshotDifferences)
  • Clone Automation Template (CloneAutomationTemplate)
  • Commit User Story (UserStoryCommitFiles)
  • Deploy a Promotion (RunDeployPromotion)
  • Execute Automation Template (ConvertAutomationToDeployment)
  • Execute Deployment (ExecuteDeployment)
  • Export Automation Template (ExportAutomationTemplate)
  • Get User Story Count (UserStoryCounter)
  • Import Automation Template (ImportAutomationTemplate)
  • Invoke Continuous Integration (RunContinuousIntegration) 
  • Invoke Copado Function (apex-copado__RunCopadoFunction)
  • Invoke Run All Apex Tests for an Org (RunAllOrgApexTests)
  • Invoke Selenium Test (RunSeleniumTest)
  • Invoke Selenium Test Group (RunSeleniumTestGroup)
  • Org Compliance Scan (RunOrgComplianceScan)
  • Org Static Code Analysis (RunOrgStaticCodeAnalysis)
  • Recalculate Branch Status  (RecalculateBranchStatus)
  • Recalculate Deployment Flow Branch Statuses (RecalculateDeploymentFlowBranchStatuses)
  • Refresh Org Metadata Cache (RefreshOrgMetadataCache)
  • Run User Story Test (RunUserStoryTests)
  • Snapshot Compliance Scan (RunSnapshotComplianceScan)
  • Take a Git Snapshot (TakeGitSnapshot)
  • User Story Compliance Scan (RunUserStoryComplianceScan)
  • User Story Static Code Analysis (RunUserStoryStaticCodeAnalysis)

For more information about each of these methods and their use, check out Copado’s API documentation.

Using an Apex Method in a Salesforce Flow

Adding an Apex method to a flow is a very simple task. You just need to drag and drop an Action item. If you filter the actions by Type and select Apex Action, you will find all Copado Apex actions available under the Action lookup field:

The parameters you need to provide will vary depending on the action selected. The example below shows an Apex action using the Get User Story Count method:

  1. Navigate to an existing Salesforce flow or build a new one.
  2. Drag and drop an Action item into the flow builder screen.
  3. To find the Copado actions more easily, you can filter by Type and then click on Apex Action.
  4. Select Get User Story Count.
  5. Provide a label and an API name for the task.
  6. Provide the environment Id, the pipeline Id, and the type:

  1. Click on Save.

Using an Apex Method in an Apex Class

Example test script:

copado.UserStoryCounter.InvocableVariables invocableVariable = new copado.UserStoryCounter.InvocableVariables();
invocableVariable.type = 'Behind';
invocableVariable.pipelineId = 'a0M0N00000WxO5fUAF';
invocableVariable.environmentId = 'a0S0N00001JONvMUAX';
List<copado.UserStoryCounter.InvocableVariables> invocableVariables = new List<copado.UserStoryCounter.InvocableVariables>{invocableVariable};

List<Integer> numberOfUSBehind = copado.UserStoryCounter.getUserStoryCount(invocableVariables);
System.debug('Number of US Ahead: ' + numberOfUSBehind[0]);

If you would like to test this script, copy and paste it in the Apex anonymous window of the Developer Console and specify the pipeline and environment record Ids and the ahead or behind value. After executing it, you will see in the debug information the count of user stories.

Using an Apex Method in a Process Builder

As mentioned above, Apex methods can also be invoked in a process builder. The process of adding an Apex action to a process builder is quite similar to that of flows. You can find the step-by-step process in the article Process Builder Integration.

How did we do?