Invoking FLOWs Via APIs

SoomjeetSahoo
3 min readMay 21, 2022

Flows are getting powerful these days, and it’s considered the most powerful no-code business automation out there. Hence, salesforce is going to discontinue Process Builder& Work Flow in favor of using Flows. Being a Pro-Code Developer, I always prefer Apex code and customized solutions over configs. Yet I found flows to be a real game-changer for implementing Semi-Complex solutions.

Let’s say you have an external system that needs to create contacts to an account in salesforce. It was traditionally implemented with ApexClass with RestResource, a very customized approach. Now with the development of Flows, we can leverage the power of configuration to meet business needs without implementing ApexClasses.

Note : For this implementation, we will be using an apex class to deserialize JSON from Apex Defined variable into an object. This is to limit the number of variables used. I doubt if this could handle complex JSON structures.

Please refer to this github repo for code and metadata reference.

Without further Ado, Let’s jump right into implementing the solution. Below mentioned is the endpoint, authorization, request body & deserializing class.

Endpoint: /services/data/v52.0/actions/custom/flow/CreateContactFlowViaAPI

Header:
Authorization : Bearer <AccessToken>

Body:

Deserialize class to be used as Apex Defined variable for Flow:

For creating the parser class, I used JSON2Apex. Remove the parse method and add AuraEnabled annotation to each variable.

Now, Let’s go through the Flow implementation.

Step 1: Create an AutoLaunched Flow.

Flow creation screen.

Step 2: Create Apex Defined variable.

Apex Defined variable

Apex takes care of deserializing the whole JSON that is passed at request body.

Step 3: Loop over the parsed variable.

Step 4: Create a contact record.

Step 5: Push all contacts into single list to be created at once.

Step 6: Create all the contacts at the end with Create Record element.

Finally the flow would look something like below

Final Flow Setup

Working Demo:

P.S. I used Postman to mimic as the External System in this example.

Resources:
If you get stuck, Please implement the metadata of the Flow directly from the Repo : https://github.com/LonelyLlama487/API_Invokable_Flow

To know more on Apex Defined variable please refer this link.

As always drop me a mail if you need my assistance. 😊

--

--

SoomjeetSahoo

Salesforce Dev @ Salesforce with lots of inquisitiveness to learn and grow in Salesforce and Node Domains. Currently 15x Salesforce Certified & 14x Super Badge.