Workflow Apex API
The Workflow Apex API starts a Doc Gen workflow from Apex code. You send a JSON payload to the workflow’s webhook, and the workflow starts with that payload as its input. Use it from queueable, future or batch Apex, scheduled code or Lightning components, for example to start an on-boarding process when a record changes. A trigger hands the call to asynchronous Apex, because Salesforce does not allow a callout directly in a trigger.
The call is a global method of the class MFAPI_Workflow, in the package namespace mfwe.
Start a workflow
sendWebhook takes one parameter object, SendWebhookParams:
| Field | Meaning |
|---|---|
webhookId | The id of the webhook of the workflow you want to start |
payload | The JSON text to send as the body of the request |
It returns the body of the response as text.
mfwe.MFAPI_Workflow.SendWebhookParams params =
new mfwe.MFAPI_Workflow.SendWebhookParams();
params.webhookId = '3f2b9a64-1c7e-4d58-9a0b-6e5d1c2f8a47';
params.payload = JSON.serialize(new Map<String, Object>{
'accountId' => '0010Y00000A1b2cQAB',
'accountName' => 'Nordlys Bygg AB',
'event' => 'Customer onboarding'
});
String response = mfwe.MFAPI_Workflow.sendWebhook(params);
System.debug(response);The instance form, sendWebhookDyn, does the same on the object that mfwe.MFAPI_Workflow.getInstance() returns:
mfwe.MFAPI_Workflow api = mfwe.MFAPI_Workflow.getInstance();
String response = api.sendWebhookDyn(params);The static method is also available to Lightning components, which can import it as an Apex method.
Details
- The call goes to the Workflow service of the software environment you chose in Workflow Software Environment, see Configuration. It is a callout, so Salesforce does not allow it after a record has been inserted, updated or deleted in the same transaction. Make the call before any such change, or run it asynchronously, for example in a queueable job.
- If the workflow answers with an error status, the call does not throw an error. It returns the body of that response, so check the text you get back.
- With the callout log on, each call is logged as a callout to
/Webhook/Catch. See Troubleshooting.