Capture Apex Action (Invocable) response?

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I'm able to successfully call an Apex Action (Invocable Method), but is there a way to capture the response? I don't see anything in the "Run Custom Apex Action" fields that account for that, but I'm wondering if there is a model reference or something that can be used to take the response (outputValues) and put it into another model field...

Photo of Paul


  • 592 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,576 Points 20k badge 2x thumb
Hi Paul, 

Yes, there is a way to capture the response / "Output Values" from a Skuid-invoked Apex Invocable Action. After an Apex action is invoked, Action-specific Merge variables are returned, depending on whether the Action succeeded or failed, which can be then used in subsequent actions or in On-Error Actions, respectively.

• If your action succeeds, subsequent Actions can refer to the response's output variables via {{$PreviousAction.result.OUTPUT_VARIABLE_NAME}}

• If your action fails, then subsequent On-Error Actions can access the error message via {{$CurrentAction.error.message}}

For example, let's say you have an Invocable Action that converts a Lead. Your Invocable Action might return a List<ConvertLeadActionResult>, where ConvertLeadActionResult is a class like this that defines Invocable Variables which will be returned, such as the converted Account Id, Contact Id, and Opportunity Id, or a String with an error message which would your Apex could return in the event of an error during the Apex lead conversion:

  global class ConvertLeadActionResult {    
    public ID accountId;
    public ID contactId;
    public ID opportunityId;
    public String error;

Assuming that the accountId, contactId, and opportunityId Invocable Variables are populated by your Apex on successful Lead conversion, then you could, for instance, query for the converted Account, Contact, and Opportunity immediately after Lead conversion and display them in a popup, by setting the value of Model Conditions to the values returned from the Custom Apex Action result, like this:

Or, if your action failed, you could a "Show message and block UI" action which displays an error message like this:

There was an error performing this Action:<br/><br/> {{$CurrentAction.error.message}}