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?

  • Did you try anything? What type of issues you are facing – Santanu Boral Feb 20 '17 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 Feb 20 '17 at 22:58

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});     

// 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.