After the release of Summer’14, it is possible to call the flows from apex classes, using Flow. Interview Class and its start method to start the flow. You can use the flow in the Visualforce page also using flow:interview component but in this case, we need to use UI and User Interaction to drive it.

The Flows in Salesforce can be triggered ready flows means a flow that can be launched without user interaction. In this case, the flows are called using Workflow actions or Process Builder. Here we are just making the Flow and call it through apex code and a scheduled class which calls the controller method to execute the flow.

Flow Example

Flow Example

About Flow

In this flow, we are getting the record from Lead make a decision if all the required fields for a hot lead is not null then we are sending an email to the owner.

Also Read: How To Embed Lightning Component In Flow

When lead is going to be saved it goes to the record variable of flow that is “new Lead” and then we are saving it to Lead fields and then proceed to the next process.

edit get records

hire salesforce developers

Flow Controller

public class FlowController {
    public FlowController(){
    public void callFlow(){
        Lead l = new Lead();
        l.FirstName = 'Sapna';
        l.LastName = 'Chandani';
        l.Email = '[email protected]';
        l.Phone = '8522256355';
        l.MobilePhone = '876545465';
        l.Company = 'Emizentech';
        insert l;
        Map<String,Lead> leadMap = new Map<String, Lead>();
        leadMap.put('newLead', l);
        Flow.Interview.Email_Flow flow1 = new Flow.Interview.Email_Flow(leadMap);

You can call this controller using VF Page

<apex:page controller="FlowController">
 <apex:form >
  <apex:commandButton action="{!callFlow}" value="Start" reRender="text"/>

Schedulable Class

global class scheduledFlow implements Schedulable {
 global void execute(SchedulableContext sc) {
  FlowController fc = new  FlowController();

If you are searching for professional salesforce consultants then reach out to us.

Also Read: How To Create A Flow In Salesforce

Avatar photo

With a decade of experience in eCommerce technologies and CRM solutions, Virendra has been assisting businesses across the globe to harness the capabilities of information technology by developing, maintaining, and improving clients’ IT infrastructure and applications. A leader in his own rights his teammates see him as an avid researcher and a tech evangelist. To know how the team Virendra can assist your business to adopt modern technologies to simplify business processes and enhance productivity. Let’s Talk.