Leverage Salesforce Flows for DevOps
- Why Leverage Salesforce Flows?
- Integrating with External Tools
- Options to Trigger the Flow
Extend and customize your Copado DevOps process by leveraging the power of Salesforce flows. Need to trigger a scan in an external tool? Need to update data externally or in Salesforce? Need to post a message on Slack? Learn how to leverage flows to integrate with APIs from external tools and update corresponding records in Salesforce.
Why Leverage Salesforce Flows?
It's a declarative and faster way to create DevOps integrations.
- Can interact with APIs and parse results with its in-built External Services.
- Can be launched on a scheduled basis.
- Can be launched from a custom button (e.g. button on the user story layout).
- Can be launched from a Process Builder.
- Can be easily triggered as part of your deployment by means of a deployment step or user story task, and also as an automation if you are working with Copado Continuous Delivery.
- Can be launched from Apex code.
- Can be published in the AppExchange.
Integrating with External Tools
It’s important to use quality testing and agile tools as part of your Salesforce DevOps process. When working with Copado’s user story-centric pipelines, you can leverage flows to integrate with any external tool (e.g. testing, agile planning, etc.) as part of your DevOps process regardless if there is an official integration with this external tool or not. Your teams are now empowered to customize and extend Copado without relying on vendors to build required integrations.
Use cases for integrating with external tools include:
- Triggering external jobs:
- You can configure your flow to trigger a job in an external tool by leveraging the external tool’s APIs. The flow remains paused to wait for the long-running external job to complete. Once the job completes, Copado will automatically create a Result record to store the job results.
- Syncing external data:
- You can configure a scheduled flow to run every 30 minutes to sync external data by leveraging the external agile tool’s APIs. For example, you can sync recently created or modified user stories in an external agile tool. The flow will request recent user story changes and save the results in Copado user stories. To sync Copado user story changes back to the external agile tool (e.g. status changes, validations, etc), you can also include a second flow that gets executed when a User Story record changes and that updates its equivalent user story in the external agile tool.
In order to get started, you need to:
- Identify which external tools you would like to integrate in your Copado DevOps process.
- Identify which endpoints are needed to achieve your DevOps automation.
- Configure External Services for the required endpoints.
- Define how to resume the flow once the long-running job completes.
- Update the corresponding Copado Result records with the results.
Identifying Which Endpoints Are Needed to Achieve Your DevOps Automation
The automation tool can be owned by a third-party vendor or an internal team in your organization. Communicate with the tool owners to get guidance on how to implement the automation you want to achieve. This can mean to simply go through their public documentation to get the required API endpoints, or to directly work with one of their team members to architect the integration.
Configuring External Services for the Required Endpoints
Salesforce External Services are a great way to access third-party services from a flow, such as quality scans or data integrations. All you need are the services’ OpenAPI schema (OAS schema), and you are good to go.
Ask the tool owners if they have configured their API endpoints as External Services on Salesforce in the past. If they do, ask them to share with you the Endpoints’ OpenAPI Schema (a JSON file for each endpoint) as this will be needed for setting up the flow. If they haven’t done this in the past, you can request them to build it or you can build it with your team.
Once you upload the OpenAPI Spec for the external service, you will find the API endpoints available when adding a new flow action:
Defining How to Resume the Flow Once the Long-Running Job Completes
After the external job is triggered, you need to pause the flow to wait for the long-running job to complete. The paused flow must be resumed in the future in order to review the job results. Flows offer two options to resume the job:
- Posting a platform event message:
- Platform event messages are the recommended option for efficiency, nevertheless this requires that the external tool implements a function to post a platform event message to your Salesforce org. This requires some programming in the external tool and credential access to post to your org. Once the flow is resumed by the platform event message, then continue to update the Copado Result records with the job results:
Example flow resumed with a platform event message.
Platform event message resume condition.
- Checking the status of the external job every few minutes:
- This is the traditional polling flow where you call out to an endpoint to check the job status. If the job status is still in progress, then you have to pause the flow to be resumed a few minutes later to check the status again. Once the job completes, continue to update the Copado Result records with the job results:
Example flow checking the status of the external job every few minutes.
Traditional polling resume condition.
Updating the Corresponding Records with the Results
When the external job completes, you will need to inform your end users (developers, testers, release managers, etc.) about the results. If the automation is meant to be triggered from a Copado user story, then you should update the user story. If the automation is meant to be triggered from a Copado deployment step, then you should update the step.
Check out the guide Building a DevOps Automation in a Flow for a more detailed process for building a flow.
Options to Trigger the Flow
Your flows can be triggered on a scheduled basis in case it’s a job that needs to run frequently. Also, you can trigger a flow from a button, like for example a button on the user story layout for running a scan or analysis with the user story metadata.
Alternatively, you can trigger flows from a new deployment step, the Salesforce Flow step, where you select the Salesforce flow you want to trigger. The step can remain paused until the flow updates the step as complete. Additionally, you will be able to add Salesforce flows as quality gate automations so that they get included automatically in any deployment that meets the quality gate criteria.
By building a Salesforce flow that triggers your external jobs, waits for the job to complete and then updates the corresponding Copado records, you can now extend and customize your DevOps process with native Salesforce platform features.