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.
- How to Use Flow inside Screens ( Rich text Component )
- Code for the Lightning Component for the Flow
- Validate Input from Flow
- Send the data from LWC to Flow and Vice Versa
- 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.
- Create a Custom Object named Student with Phone, Email and About Me ( Rich Text Area ) field
- Develop a Screen which will display the input to enter the information by the User
- Create Record Element Which Will Create Student Record
- 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
- Lead Status is changed to Qualified
- Lead Rating is Hot
- Lead Source is Partner Referral
- Lead Owner is a User
SFDCPanther Approach
Invocable Apex
- Invocable methods are used to provide extra functionality for Salesforce flows and with the help of Invocable apex, flows are becoming more powerful.
- You can also use Invocable methods to Replace your triggers. ( Flow + Invocable ~= Apex Trigger )
- Use the InvocableMethod annotation to identify methods that can be run as invocable actions.
Invocable Method Considerations
- The invocable method must be static and public or global, and its class must be an outer class.
- Only one method in a class can have the InvocableMethod annotation.
- Other annotations can’t be used with the InvocableMethod annotation
Inputs and Output Considerations
- A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
- A list of the generic sObject type (List<sObject>) or a list of lists of the generic sObject type (List<List<sObject>>).
- 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-13-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='Status of the Lead Convert' description='Status of the Lead Convert')
public String status;
@InvocableVariable(label='Error Message if any' description='Error Message if any')
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
Recording
Thanks for reading 🙂
I will share more scenarios soon.