Implementing a Call Using a Record-Triggered Flow (Automatic Trigger)
One way to make the callout using a Callout Template is automatically with a Record-Triggered flow. This method is asynchronous. The flow only initializes the callout, the actual callout runs in a different transaction. If you need the transaction to happen in the same transaction, use the synchronous flow action or the screen flow component.
Invoke a callout automatically with a Record-Triggered Flow
To use the Callout Template in a record-triggered flow, you will start by going into Set Up and selecting Flows under Process Automation (be sure to check out Salesforce documentation on Flows as well!). Click “New Flow” and select “Record-Triggered Flow”. Add your object and enter conditions for when the flow is triggered, and make sure to select “Actions and Related Records” when asked “Optimize the Flow for”.
Now, you can add an Action element to the flow. As an Action, search for “Invoke Callout”. You can reference the callout template by using the Template Developer Name or using the Template Id. Using the Developer Name action is recommended because it makes it easier to deploy and doesn’t hardcode record ids into your Salesforce setup.
If you are using the Template Developer Name, you need to provide the Template’s developer name. If you’re using the Template Id, you need to provide the Template’s Id. You can identify your Callout Template Id or Developer Name under the Administration tab, Callout Templates subtab in the Declarative Webhooks app. If there is no Developer Name displayed, it means you are using an older version of the template. To generate the developer name, edit the callout template, save and the developer name will be automatically generated.
After providing a label, name and description, set the Input Values. You have to provide the record Id that is going to be used for this callout. You can use the record that started the flow or a related record.
Be sure to Activate your process and test by either creating or editing a record associated with your Main Object.
We recommend testing this in your Sandbox before Production.
If you want to review the callout logs of the automated process you have created, return to the Declarative Webhooks app and select the Call Logs tab.
Calls might be delayed
When making calls with the “Invoke Callout” flow actions, the callout might not run right away. Depending on context, number of records / callouts and the governor limits, Declarative Webhooks takes a decision on when to make the actual callouts.
- It can run in a few seconds if the algorithm decides @future, Queueable or Batch Apex are the best options
- It can run in a couple of minutes if Declarative Webhooks decides a Scheduled Apex is the available option
- It can take up to an hour if the algorithm cannot find another option. The list of calls affected by this decision and waiting to be picked up by the job are found in the “Waiting Callouts” subtab from the Administration page.