This document discusses calling a flow from Apex. It describes creating an Apex class that inserts an Opportunity record, passes it as a parameter to a flow, and starts the flow. The flow waits one minute then retrieves the Opportunity record, checks if it was created, and generates a task for it.
This document discusses calling a flow from Apex. It describes creating an Apex class that inserts an Opportunity record, passes it as a parameter to a flow, and starts the flow. The flow waits one minute then retrieves the Opportunity record, checks if it was created, and generates a task for it.
This document discusses calling a flow from Apex. It describes creating an Apex class that inserts an Opportunity record, passes it as a parameter to a flow, and starts the flow. The flow waits one minute then retrieves the Opportunity record, checks if it was created, and generates a task for it.
This document discusses calling a flow from Apex. It describes creating an Apex class that inserts an Opportunity record, passes it as a parameter to a flow, and starts the flow. The flow waits one minute then retrieves the Opportunity record, checks if it was created, and generates a task for it.
Let's begin by initiating the creation of an autolaunched
flow We aim for this flow to execute after a brief delay.As a demonstration, we'll configure the flow to execute after a predefined waiting period of one minute.
We need to establish a variable resource called
"newOpp,which should be accessible for input from Apex. Retrieve the records utilizing the resource variable obtained from the Apex class. We're incorporating a decision element to verify if the record has been successfully created. Generate a task for the opportunity. APEX CLASS
public class FlowController {
public void callFlow() { // Set up Opportunity record as an example Opportunity l = new Opportunity(Name='FlowCalling',CloseDate=Date.newInstance(2024, 4, 22),Amount = 20000,StageName='Prospecting'); insert l;
// Prepare the Flow variables
Map<String, Object> params = new Map<String, Object>(); params.put('newOpp', l);
// Instantiate and start the Flow
Flow.Interview.FlowCallFromApex yourFlow = new Flow.Interview.FlowCallFromApex(params); yourFlow.start(); } }
FlowController obj=new FlowController();
obj.callFlow(); Initially, we'll verify the creation of the opportunity via the Apex class. The parameters are passed to the flow, and after one minute, the task is created using the flow.