Leverage Salesforce Flows for DevOps

Updated 2 weeks ago by Copado Solutions

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.

As part of the Winter ‘21 release coming soon, Copado will be launching a deployment step and a user story task that will allow you to trigger a Salesforce flow as part of your DevOps process and run a Salesforce flow as a quality gate. Stay tuned!

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:

  1. Triggering external jobs:
    1. 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, you can save the results in Salesforce records.
  2. Syncing external data:
    1. 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:

  1. Identify which external tools you would like to integrate in your Copado DevOps process.
  2. Identify which endpoints are needed to achieve your DevOps automation. 
  3. Configure External Services for the required endpoints.
  4. Define how to resume the flow once the long-running job completes.
  5. Update corresponding 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.

There are some great examples of how to register external services here, with a more detailed example of how to generate an Apex client and explore the schema, here.

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:

  1. Posting a platform event message:
    1. 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 records on Salesforce with the job results:
Example flow resumed with a platform event message.



Platform event message resume condition.

  1. Checking the status of the external job every few minutes:
    1. 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 records in Salesforce 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.

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. 

As of Copado Winter ‘21 (coming soon), you can also 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.

Conclusion

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.


How did we do?