Salesforce has introduced a new feature called Invocable.Action in Apex, which allows you to call invocable actions directly from your Apex code.
Raptbot Technologies Private Limited
Elevate Your Business with Raptbot: Your Premier Salesforce Partner for Innovation, Integration, and Unmatched Expertise
Here's a breakdown of how you can use it:
1. What is Invocable.Action?
???- It's a new Apex class that enables you to make calls to invocable actions from within your Apex code.
2. How to Use Invocable.Action:
???- Reference Invocable.Action in your Apex code.
3. Example 1: Posting to Chatter
???- The provided example demonstrates calling the standard invocable action named chatterPost to post a message to the current user’s Chatter feed.
???- You create an instance of Invocable.Action, set the required parameters (like the text of the post and the target record), and then invoke the action.
???- The results, such as the success of the action and any output parameters, can be processed in your Apex code.
领英推荐
public class MyApexClass {
public void postToChatter(String recordId) {
Invocable.Action action = Invocable.Action.createStandardAction('chatterPost');
action.setInvocationParameter('text', 'This is an example Chatter post.');
action.setInvocationParameter('subjectNameOrId', recordId);
List<Invocable.Action.Result> results = action.invoke();
if (results.size() > 0 && results[0].isSuccess()) {
System.debug('Created feed item with ID: ' +
results[0].getOutputParameters().get('feedItemId'));
}
}
}
4. Example 2: Custom Invocable Action
???- Another example shows calling a custom invocable action named Doubler.
???- Similar to the first example, you create an instance of Invocable.Action, set input parameters, invoke the action, and handle the results.
public class MyApexClass {
public void doubler(Double input) {
Invocable.Action action =Invocable.Action.createCustomAction('apex', 'Doubler');
action.setInvocationParameter('input', 1);
List<Invocable.Action.Result> results = action.invoke();
if (results.size() > 0 && results[0].isSuccess()) {
System.debug('Result is: ' + results[0].getOutputParameters().get('output'));
}
}
}
In simple terms, this update allows developers to easily integrate and execute invocable actions directly within their Apex code, making it more convenient to work with and process the results of these actions.