5

This seems like it should be easy but I'm having a lot of trouble finding any resources from after 2014. It's a rather simple scenario. I have a Flow and need to invoke it from an Apex Trigger + Class (it's before delete/after undelete, so Process Builder won't suffice).

It's a very simple process too. Just grab a field value, assign it to the Flow variable. Is this possible?

2
  • Did you try anything? What type of issues you are facing Commented Feb 20, 2017 at 22:56
  • 1
    I'm brand new to Apex (and coding). I haven't tried anything yet because I have found zero resources showing how to achieve it. There was something involving Controllers and VF, but I don't have any experience or even cursory knowledge of those... I was hoping for a simple way to define a method, pass in parameters and invoke with a Trigger.
    – Mike
    Commented Feb 20, 2017 at 22:58

1 Answer 1

10

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 has 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');

Doc refs: Getting variables from flows and Setting variables into Flow

Your flow variables to be declared of type input/output as appropriate. Reference to variables is case-sensitive

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .