Hello #Trailblazers,

Welcome back and in this blog post, we will discuss three different scenarios related to flow. So let's start.

Complete Code

You can get access to all the flow Here

Before We start

Before we actually start talking about the salesforce let's talk about when to use which flow.

Flow Scenario 1 -

Create a Screen Flow to Display the Input screens for Creating Student Record. Also, Display the Success Screen and Url to New Record.

In this screen flow, you also need to display the rich text area as an input. As Salesforce Flow does not have a Rich text Area Component so we will use the LWC Component. Here is what we will do.

Show How to use Lightning Web Component inside Salesforce Screen Flows.

  1. How to Use Flow inside Screens ( Rich text Component )
  2. Code for the Lightning Component for the Flow
  3. Validate Input from Flow
  4. Send the data from LWC to Flow and Vice Versa
  5. Show case an Existing Component

1 - Navigate to Setup -> Search For Flows -> Click on New Flow

2 - Then Select Screen flow

Below are the steps that we will have to follow in order to develop the complete flow.

  1. Create a Custom Object named Student with Phone, Email and About Me ( Rich Text Area ) field
  2. Develop a Screen which will display the input to enter the information by the User
  3. Create Record Element Which Will Create Student Record
  4. Success Screen which will display Success Information

Student Information Input Screen

Create Record Element Screen

Success Flow

Complete Flow

Flow Scenario 2 -

Auto Convert a Lead When

  1. Lead Status is changed to Qualified
  2. Lead Rating is Hot
  3. Lead Source is Partner Referral
  4. Lead Owner is a User

SFDCPanther Approach

Invocable Apex

  1. Invocable methods are used to provide extra functionality for Salesforce flows and with the help of Invocable apex, flows are becoming more powerful.
  2. You can also use Invocable methods to Replace your triggers. ( Flow + Invocable ~= Apex Trigger )
  3. Use the InvocableMethod annotation to identify methods that can be run as invocable actions.

Invocable Method Considerations

  1. The invocable method must be static and public or global, and its class must be an outer class.
  2. Only one method in a class can have the InvocableMethod annotation.
  3. Other annotations can’t be used with the InvocableMethod annotation

Inputs and Output Considerations

  1. A list of a primitive data type or a list of lists of a primitive data type â€" the generic Object type is not supported.
  2. A list of the generic sObject type (List<sObject>) or a list of lists of the generic sObject type (List<List<sObject>>).
  3. A list of a user-defined type, containing variables of the supported types above or user-defined Apex types, with the InvocableVariable annotation.

Here is the Apex Code for the Invocable Action

/**   * @description       : This class is used to convert the Lead using Flow   * @author            : Amit Singh   * @group             : Flow   * @last modified on  : 12-11-2021   * @last modified by  : Amit Singh  **/  public with sharing class ConvertLeadUsingFlows {        @InvocableMethod(label='Lead Convert Using Apex' description='Convert the Lead Record Using Apex' category='Lead')      public static List<ConvertLeadUsingFlows.OutputWrapper> LeadConvert(List<Id> LeadIds){          /* Get the MasterLabel from LeadStatus Object using SOQL where isConverted is True and Store the MasterLabel */          LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];          /* Create the list of Database.LeadConvert */          List<Database.LeadConvert> leadConvertList = new List<Database.LeadConvert>();          for(Id LeadId : LeadIds){              Database.LeadConvert lc = new database.LeadConvert();              lc.setLeadId(LeadId);              lc.setConvertedStatus(convertStatus.MasterLabel);              //lc.setDoNotCreateOpportunity(true);              leadConvertList.add(lc);          }          List<Database.LeadConvertResult> leadConvertResult = Database.convertLead(leadConvertList);          return new List<ConvertLeadUsingFlows.OutputWrapper>();      }      /*          Input Parameters              Apex Input          Flow Input              List<T>         ~=  Id              List<List<Id>>  ~= List<Id>      */        public class OutputWrapper{          @InvocableVariable(label='Records for Input' description='yourDescription')          public String status;          @InvocableVariable(label='Records for Input' description='yourDescription')          public String message;      }  }  

Follow the steps to Create the Flow and Select Record Triggered Flow. For Object select lead and see below image for other conditions

Step2 - Check if the Lead Status is Changed to Qualified

Step3 - Call the invocable action

Complete Flow

Thanks for reading 🙂

I will share more scenarios soon.

Also, the recording for the above scenarios will be shared soon.