function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aneesha SAneesha S 

Call auto launched flow from apex trigger

Hello,

i am am trying to run an auto launched flow from an apex trigger. I have code to invoke flow in an apex class method which is called from a  trigger. However on execution I see that the flow is not launched. I am able to run the flow from process builder just fine. Is there anything that I'm missing?
NagendraNagendra (Salesforce Developers) 
Hi Aneesha,

To invoke a flow from a class and pass in values to the Flow's variables:
Flow.Interview flow = new Flow.Interview.MyFlowApiName(new map<String,Object> 
                                                {'vAccountId' => aId});     
flow.start();

// after flow as executed, fetch values from Flow's variables 
//       (assumes flow creates an Order and a Contact)
Order ord   = (Order) flow.getVariableValue('oOrder');
Contact c   = (Contact) flow.getVariableValue('oContact');
Your flow variables to be declared of type input/output as appropriate. Reference to variables is case-sensitive

Doc refs: Getting variables from flows and Setting variables into Flow. Hope this helps.

Please mark this as solved if my reply was helpful.

Thanks,
Nagendra.
 
Aneesha SAneesha S
Hello Nagendra,

Thanks for your response.

I am doing this. However unable to trigger it from apex handler for a trigger. Is there any limitation like that?