Hi,
We can launch a flow from Apex in the following ways
Invoking the flow from Apex Statically:
Without Namespace:
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('AccountID','001XXXXXXX');
inputs.put('OpportunityID','006XXXXXXX');
Flow.Interview.Calculate_discounts myFlow =
new Flow.Interview.Calculate_discounts(inputs);
myFlow.start();
With Namespace:
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('AccountID','001XXXXXXX');
inputs.put('OpportunityID','006XXXXXXX');
Flow.Interview.myNamespace.Calculate_discounts myFlow =
new Flow.Interview. sftech.Calculate_discounts(inputs);
myFlow.start();
Invoking the flow from Apex Dynamically:
Without Namespace:
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('AccountID','001XXXXXXX');
inputs.put('OpportunityID','006XXXXXXX');
Flow.Interview myFlow = Flow.Interview.createInterview('Calculate_discounts', inputs);
myFlow.start();
With Namespace:
Map<String, Object> inputs = new Map<String, Object>();
inputs.put('AccountID','001XXXXXXX');
inputs.put('OpportunityID','006XXXXXXX');
Flow.Interview myFlow = Flow.Interview.createInterview('sftech', 'Calculate_discounts', inputs);
myFlow.start();
Here Calculate_discounts is the name of the flow.
AccountID and OpportunityID are input variables of the flow.
sftech is the namespace
How to get variable values from flow to Apex?
system.debug('My Output Variable: ' + myFlow.getVariableValue('varName'));
Note: We can invoke flow from Apex if the flow type is "Autolaunched Flow (No Trigger)" only
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/flow_interview_class.htm#apex_Flow_Interview_methods