Flow Calling From Apex

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Implementing Calling Flow from Apex

Streamlining Salesforce Automation

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.

You might also like