Execute Apex Action
Use this type of Action whenever you want to call a method from Work Relay API, or even your custom Apex class.
With Work Relay API checkbox checked, you are offered to choose a class and a method from the API, and the list of parameters you should enter to run the method:
Some Examples of using Work Relay API
Execute Action Group
- Select
GlobalActionService
in API Class Name (1), selectExecuteActionGroup
method (2):
- Populate
groupId
with Global Action Group Id (3):
To get the Global Action Group Id go to the Actions -> Action Groups, open the Action group you need and grab Id (4):
- (Optional) populate Source (5):
In source you can pass a JSON Array which contains sources for each action from your Action Group. There are 2 ways you can pass sources:
1. Pass Action IDs with record ID for each action: "{Action1_ID}":"{record1_Id}", "{Action2_ID}":"{record2_Id}",...
2. Pass Object Name and Record ID. All Actions which use specified object as a source will use specified record ID: "{Object1_API_Name}":"record1_Id", "{Object2_API_Name}":"record2_Id",...
For example:
if there are 4 actions in the group;
3 of them use Account as Source object;
1 of them uses Contact;
and you pass: "Account":"{Account.Id}", "Contact":"{Contact.Id}"
in this case 3 actions will get the same Account.Id
as source and 1 will get Contact.Id
(Optional) populate variables (6):
To call your custom Apex, put those calls inside of a class that will implement one of the Work Relay interfaces, WR_BPM.WorkflowCallApexActionInterface
. Here's an example of such class:
public with sharing class WorkRelayApexCalls implements WR_BPM.WorkflowCallApexActionInterface
{
public void run(sObject context, WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor, String operationType, String parameter)
{
Map <String, String> params;
if(parameter != null) params = (Map<String, String>)JSON.deserialize(parameter, Map<String, String>.class);
if(params != null && params.get('callType') == 'doSomething')
{
String paramToDoSomething = params.get('paramToDoSomething');
//your code for doing something
}
else if (params != null && params.get('callType') == 'doSomethingElse')
{
//your code for doing something else
}
}
}
This example implies that you are unifying usage of Work Relay calls of your custom code inside one class, WorkRelayApexCalls
, but whether you want to have it this way or create multiple classes for logical separation, is up to you.
Parameters received by the run
method are:
-
sObject context
: process instance's context record -
WR_BPM__Flow_Instance_Cursor__c flowInstanceCursor
: cursor that "owns" the step in the instance -
String operationType
: Proceed/Approve/Reject -
String parameter
: whatever parameters passed from the action as JSON.
The screenshot below illustrates how this class's call is made (7) from the Process builder:
Check Execute in background checkbox (8) whenever you need to perform this call in asynchronous manner.
0 Comments
Add your comment