In Spring 23 salesforce announced HTTP Callout (Beta), where you can do the HTTP Callout in Salesforce flow without code.
One of the most powerful features of Salesforce Flow is its ability to make HTTP callouts, enabling seamless integration with external systems and services. In this blog post, we will explore the concept of HTTP callouts in Salesforce Flow, understand their importance, and walk through a step-by-step guide on how to perform HTTP callouts to external services through GET and POST requests. Let’s dive in!
Table of Contents
How Do I Create HTTP Callout in Salesforce Flow?
Please find the below steps to create a callout in the salesforce flow.
Today we will connect external Systems i.e., https://dummy.restapiexample.com/. We will perform GET and POST requests using salesforce flow.
Read the best salesforce Books: Click Here.
Can we make a callout from Flow in Salesforce?
1. Create an External Credential
External credentials represent the details of how Salesforce authenticates to an external system via an authentication protocol. It also links to a user’s permission set.
To create go to ->Setup -> Home -> Named Credentials -> External Credentials -> Then click New.
2. Create an External Credential Principle
Earlier we specify the permission set to external credentials now we are mapping the principle to the permission set.
3. Create Permission, Map External Credential Principle, and Assign User.
Create a permission set and map the external credential principle to it. Next, we can assign it to any person.
In the Permission set detail page search “External Credential Principal Access” and add the principle.
Next, Assign the User to the permission set.
4. Create a Named Credential.
A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. To simplify the setup of authenticated callouts, specify a named credential as the callout endpoint.
Go to->Setup->Home ->Search Named credential -> Click New.
GET HTTP Callout in Salesforce Flow
Here in the screen flow first will use the GET callout. So, from the user I will ask for the Employee Number, next I will get the employee information from the Database.
GET EndPoint: https://dummy.restapiexample.com/api/v1/employee/1
First, in the screen flow, I will ask the user to enter the Employee Number and capturing in a text field.
Next, add an action element and choose “Create HTTP Callout”.
Give a name to the External Service and Select the named credential created in step 4.
In Configure Invocable Action choose the HTTP Method and add the Label.
In Set URL Path and the endpoint. It must always start with Slash.
Then in Provide Sample Response, add a sample response. Click Review. Based on the response passed salesforce will show you the data structure of the JSON. Then click Done.
Next in New Action choose the label and API Name and in Set Input Values for the Selected Action choose the screen component element.
In our example, I have created a text component to store employee number. I will choose that here. The click done.
Now you are done with GET HTTP Callout using Flow. Next, you can add a decision element to check the response code as below.
So If the response code is 200 then I’m showing employee details in one more screen.
Add a screen element to the canvas to add a display text component and add the required information to show.
Also in case the response is not equal to 200 then we can show the default exception as below, through the screen element.
Note: If you navigate to the external service in home then you can see Salesforce has created an external service for you based on the input you have configured in flow.
Also, You can also see the apex class created in the Dynamic Apex class section. These classes are also created by Salesforce based on the request & response that you have configured in Flow.
You are done with GET Callout.
POST HTTP Callout in Salesforce Flow.
In POST callout we will create an employee record in the database. So to do that will ask the first user to enter the required information through a screen.
Add the screen element to the canvas and add two number components and one text component as below.
Next, add the action and click the Create HTTP callout button.
In Create External Service, choose the Name and Choose the Named credential created, Then click Next.
In Configure Invocable action add the label and choose the Method.
Method : POST(Beta)
Then in the Set URL Path add the callout endpoint. The URL Path must always start with Slash.
Next in Provide Sample Request, add the employee creation JSON, click review and Review the Data structure next click Done.
Add the response JSON to the Provide Sample Response, Next review the data structure, and click done.
In the New Action page, you can see action is prepopulated, this will come from the salesforce external service and HTTP callout action. This section to add the action element to the flow.
Give a Label and API name. In Set Input Values for the Selected Action, click the body.
Create a new resource that is used as an input request body to the API.
- Choose Resource Type: Variable.
- API Name : varPostReqBody
- Data Type: Apex Defined.
- Apex Class: Search External Service name here then you can see several apex classes will appear based on the name. Then select the first data type that ends with ‘_IN_body’. This data type is for the request body that we need to send to the API.
- This apex class was created by Salesforce automatically based on the response body you have provided.
- Next, Click Done.
Choose the resource that is created in the body and click done.
Next Before calling the POST Endpoint, we need to set the values for the request body. To do that click the Plus icon before the POST Action you have created.Add the Assignment element,
- Add Label and API.
- In Set Variable Values.
- Select the resource [The Body you have created in the above step].
- From the body choose the field and map the values of the screen element, as below.
- Then Click Done.
Now you are done with POST HTTP Callout using Flow. Next, you can add a decision element to check the response code as below.
So If the response code is 200 then I’m showing created employee details in one more screen with the employee ID created in the database.
Add a screen element to the canvas and add a display text component and add the required information to show.
Also in the case of response is not equal to 200 then we can show the default exception as below, through the screen element.
Connect GET & POST Execution based on the user choice.
Here I have added an initial screen in starting of the flow where the user will choose GET or POST. The user will choose the choice by selecting the radio button. To select that I have created two choices as below.
Crate Employee choice.
Get Particular Employee Information choices.
Next added a decision element, to reroute the user to the proper Callout. In the decision, I have compared the value of the Radio button to the choice value below.
HTTP Callout Flow Configuration Demo
HTTP GET & POST Callout Demo
In this blog you have understood using HTTP GET and POST callouts in Salesforce Flow enables easy connections with external systems, allowing data to be fetched and sent in real time. If you have any questions feel free to comment. Please follow our other blog post on Salesforce Flow and Aura.
Note: For the best experience please use other public APIs available as I see inconsistent results in the endpoints.
- HTTP Callout
- Read the best salesforce Books: Click Here.
- HTTP Callout in Salesforce Flow Without Code [GET & POST]
- How to Invoke a Flow from a Lightning Web Component
- How to update child records using salesforce flow
- How to Assign records to Queue using Salesforce Flow?
- How to create a Data Table in Salesforce Flow : Complete Guide.
- How to retrieve record Type Id in flow
- How to navigate record detail page in flow
- How to send email using flow in salesforce
- How to Display Icon In Lightning Datatable
- How to Create Record in lightning Component
- How to Delete Multiple Records Using Checkbox In Lightning Component.