+ Start a Discussion
StaciStaci 

Can you call a Flow in Apex class?

How do you call a Flow from an Apex class and feed it a record id? Please provide specific example

Jeff MayJeff May

The approach is to use a VF page and controller.  The Apex class (or even a custom button) builds the URL to the VF page and the controller sets the params to the Flow.  For specifics, refer to the Flow Designer Dev Guide.

amidstcloudamidstcloud

No . You cannot access FLow in Apex . In salesforce , We cannot query information about flow.Its not exposed to developer . we can make a Metadata Callout to get information but this also contain very basic information(Metadata) .  

 

 

 

Arun NairArun Nair
Have you got a solution for this ? I am trying to call a Flow from apex using Flow.Interview.start() method.But it is goving runtime exception as
common.apex.runtime.impl.ApexExecutionException: Start can only be called on a trigger-ready flows

Any workaround for this?
acousticacoustic
It is now possible with Trigger Ready flows (submit a case with SF support to get into the Pilot) . Here is a great post for implementing it: http://andyinthecloud.com/2014/10/26/calling-flow-from-apex/ you can freely pass variables between flows and APEX classes/Triggers

Best,

Alex
Pedro Espada Manuel AccPedro Espada Manuel Acc
Yes sure.
The way that you have to use is as follow:
 
//Creating a Map to pass parameters to the flow. For example
Map<String, Object> flowMap = new Map<String, Object>();
flowMap.put('request', new Case(Id = requestId));


//Instantiating and launching the flow with the parameters
Flow.Interview.Unique_Name_Flow myFlow = new Flow.Interview.Unique_Name_Flow myFlow(flowMap);
myFlow.start();

//Getting Output parameters from the flow
 String localOutputParameter = (String)myFlow .getVariableValue('outputParameter');

Regards