Automation Champion

Automating Salesforce One Click at a Time
Automation Champion
  • Home
  • About Me
    • Testimonials
    • Resources
  • Process Builder
  • Salesforce Flow
  • Pardot
  • Apex
  • Training Details
    • Salesforce Administrator
    • Salesforce Advanced Administrator
    • Platform App Builder
    • Lightning Flow
    • Pardot
    • Sales Cloud
    • Service Cloud
    • Community Cloud
    • Hands-on Excercises
  • My Books
  • Contact Me
  • Tag: Process Builder Salesforce

    • Getting Started with Salesforce Flow – Part 43 (Dynamic Approval Routing in Salesforce)

      Posted at 1:12 AM by Rakesh Gupta, on January 2, 2021

      Big Idea or Enduring Question:

      How do you set up dynamic approval routing?

      In Salesforce, a user can use an Approval process to get approval from managers or higher authority. Approval processes route a record to one or more approvers, specifying the steps necessary for a record to be approved, and who must approve it at each step.

      In a normal approval process, i.e., Static approval process, the approvers at each step are explicitly specified in each step approval process, or you can have the submitter choose the approver manually, as shown in the following screenshot: Whereas dynamic approval routing allows us to specify the approvers for each record using User lookup fields on the record requiring approval. These fields can be populated using Process Builder or Apex, using data from a special custom object/setting that contains all the information needed to route the record. Dynamic approval routing provides the flexibility to route the approval request to different people based on Account Type or some other criteria related to the record. Let’s start with a business use case.

      Objectives:

      After reading this blog post, the reader will be able to:

      • Use Before-save Record-Triggered Flow to route approval requests to designated approvers
      • Use a Decision element to find – record variable or record collection variable contains a record or not
      • Use an Assignment element to assign default approver to opportunity 

      Business Use case

      Steven Greene is working as a System administrator in Universal Container. He has received a requirement from the management to route opportunity approval requests to designated approvers based on the opportunity’s Lead Source and the opportunity’s account Type.

      Automation Champion Approach (I-do):

      While this can be solved using various automation tools like Apex or Flow, we will use Before-save Record-Triggered Flow. This is not something that can be accomplished with Workflow Rules or Process Builder. 
       
      Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
       

      Let’s begin building this automation process.

      Guided Practice (We-do):

      There are 5 steps to solve Steven’s business requirement using Salesforce Flow. We must: 

      1. Create a custom lookup (with User object) field on the object being approved
      2. Create a custom object that will be used as an approval matrix
      3. Populate the approval matrix, i.e., create a few records in a custom object 
      4. Create an approval process 
      5. Salesforce Flow Steps:
        1. Define flow properties for record-triggered flow
        2. Add a get records element to find opportunity owner
        3. Add a decision element to check the record collection variable (from step 5.2)
        4. Add an assignment element  – assign dynamic approver
        5. Add an assignment element  – assign default approver

      Step 1: Creating a Custom lookup (user) 

      On the Opportunity object, create a lookup field called Opportunity Approver as mentioned in the steps below. 

      1. Click Setup.
      2. In the Object Manager, type Opportunity.
      3. Select Fields & Relationships, then click New.
      4. Select Lookup Relationship as Data Type, then click Next.
      5. Select the User object for the Related To option, then click Next.
      6. Enter Field Label and click the Next button. The API Name will populate. 
      7. As a best practice, always input a description. 
      8. Set the Field-level Security for the profiles, make sure to set this field as read-only. 
      9. Add this field to Page Layout.
      10. Click Save.

      Step 2: Create a Custom Object 

      The next step is to create a custom object Approver Matrix and a few custom fields to store related information which will use in approval routing. 

      1. Click Setup.
      2. In the Object Manager, click Create | Custom Object.
      3. Now create a custom object Approver Matrix and fields as shown in the screenshot below: 
      4. Click Save.

      Field Name Values
      Lead Source Web
      Phone Inquiry
      Partner Referral
      Type Existing Customer – Downgrade
      Existing Customer – Replacement
      Existing Customer – Upgrade
      New Customer

      Step 3: Create Approval Matrix Records 

      The next step is to create approval matrix records that associate the Lead Source and Type to the appropriate Opportunity Approver. For example, if Lead Source = Web and Type = Existing Customer – Upgrade, then one might route the records to Adam Smith as Opportunity Approver. It will look like the following screenshot:

      Step 4: Create an Approval Process 

      1. Click Setup.
      2. In the Quick Find box, type Approval Processes.
      3. Clicks on the Create New Approval Process | Use Standard Setup Wizard button. 
      4. Select the Opportunity object for Manage Approval Processes For drop-down. 
      5. Now create an approval process, as shown in the following screenshot:

      Make sure to modify the approver step (Step 3), and select related user Opportunity approver, as shown in the preceding screenshot. 

      Step 5.1: Salesforce Flow – Define Flow Properties 

      1. Click Setup.
      2. In the Quick Find box, type Flows.
      3. Select Flows then click on the New Flow.
      4. Select the Record-Triggered Flow option and click on Next and configure the flow as follows: 
        1. How do you want to start building: Freeform
        2. Trigger the Flow When: A record is created or Updated
        3. Run Flow: Before the record is saved
        4. Object: Opportunity
      5. Select Any Condition Is Met (OR). 
      6. Set Conditions
        1. Row 1
          1. Field: Opportunity | Type
          2. Operator: Does Not Equal 
          3. Value: {!$GlobalConstant.EmptyString}
      7. Click Add Condition
        1. Row 2
          1. Field: Opportunity | Lead Source
          2. Operator: Does Not Equal 
          3. Value: {!$GlobalConstant.EmptyString}
      8. Choose the Option to Every time a record is updated and meets the condition requirements.
      9. Click Done.

      Step 5.2: Salesforce Flow – Adding a Get Record Element

      The next step is to get the Opportunity Approver. We will use the Get Records element. To do this drag-and-drop Get Records element onto the canvas and map the fields according to the details below:

      1. Under Toolbox, select Element. 
      2. Drag-and-drop Get Records element onto the Flow designer. 
      3. Enter a name in the Label field; the API Name will auto-populate.
      4. Select the Approver Matrix object from the dropdown list.
      5. Select All Conditions Are Met (AND). 
      6. Set Filter Conditions
        1. Row 1:
          1. Field: Type
          2. Operator: Equals
          3. Value: {!$Record.Type}
        2. Row 2:
          1. Field: Lead Source 
          2. Operator: Equals
          3. Value: {!$Record.LeadSource}
      7. How Many Records to Store:
        1. select Only the first record
      8. How to Store Record Data:
        1. Choose the option to Automatically store all fields. 
      9. Click Done.

      Step 5.3: Salesforce Flow – Using Decision Element to Check Record Variable Size

      Now we will use the Decision element to check the Record Variable from step 5.2 size. If the Text Variable is not equal to null, then we will go ahead and update Approver on the opportunity record. Otherwise, we will update it with a default approver.

      1. Under Toolbox, select Element. 
      2. Drag-and-drop Decision element onto the Flow designer. 
      3. Enter a name in the Label field; the API Name will auto-populate.
      4. Under Outcome Details, enter the Label the API Name will auto-populate.
      5. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
        1. Row 1:
          1. Resource: {!Opportunity_Approver}
          2. Operator: Is Null 
          3. Value: {!$GlobalConstant.False}
      6. When to Execute Outcome: If the condition requirements are met
      7. Click Done.

      Step 5.4: Salesforce Flow – Using Assignment Element to Update Opportunity Approver 

      The next step is to update an Opportunity record. We will use the Assignment element, as we are using before-save flow. 

      1. Under Toolbox, select Element. 
      2. Drag-and-drop Assignment element onto the Flow designer. 
      3. Enter a name in the Label field; the API Name will auto-populate.
      4. Set Variable Values
        1. Row 1:
          1. Field: {!$Record.Opportunity_Approver__c}
          2. Operator: Equals
          3. Value: {!Opportunity_Approver.Opportunity_Approver__c} (Record variable from step 5.2) 
      5. Click Done.

      Step 5.5: Salesforce Flow – Using Assignment Element to Update Default Approver 

      In case there aren’t any approvers that exist in the Approver Matrix for the current opportunity, then we will update Opportunity Approver to Logged-In user’s manager. We will use the Assignment element, as we are using before-save flow. 

      1. Under Toolbox, select Element. 
      2. Drag-and-drop Assignment element onto the Flow designer. 
      3. Enter a name in the Label field; the API Name will auto-populate.
      4. Set Variable Values
        1. Row 1:
          1. Field: {!$Record.Opportunity_Approver__c}
          2. Operator: Equals
          3. Value: {!$User.ManagerId}
      5. Click Done.

      In the end, Steven’s Flow will look like the following screenshot:

       Once everything looks good, perform the steps below: 

      1. Click Save.
      2. Enter Flow Label the API Name will auto-populate.
      3. Click Show Advanced.
      4. Type: Record-Triggered Flow
      5. API Version for Running the Flow: 50
      6. Interview Label: Dynamic Approval Routing {!$Flow.CurrentDateTime}
      7. Click Save. 

      Almost there! Once everything looks good, click the Activate button.

      Proof of Concept

      Now onwards, if a business user updates the Lead Source and Type, Process Builder will automatically populate the Opportunity Approver field.

      1. Currently, Opportunity Approver on opportunity West Mountain Sign is Patrick Trevenen (which is correct based on our matrix which we set up in step 3)as shown in the following screenshot:
      2. Now we update the Type to Existing Customer – Upgrade and Lead Source to Web.
      3. Finally, submit an Opportunity record for approval.

      Formative Assessment:

      I want to hear from you!  

      What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? 

      Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

      Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

      Posted in Salesforce Flow | 3 Comments | Tagged Add Criteria Proces builder, Advance flow, approval process, Approver Matrix in Approval process, Approver Matrix in Salesforce, Before save flow, Choose approver dynamically, Choose approver dynamically in Salesforce, Create dynamic approval process, Decision element in Flow, developer release exam, Dynamic Approal routing Salesforce, Dynamic Approal routing Salesforce Using Flow, Dynamic approval, Dynamic approval process, Dynamic approval process in Salesforce, dynamic approval routing, Dynamic Approval Routing in Salesforce, Enable Process Builder, Evaluate the rule when a record is created, flow, Flow and PB examples, Flow and Prcoess Builder examples, FLow and Process builder example, Flow builder, flow builder in salesforce, flow builders, Flow Example, Flow examples, Flows, Getting started with Process Builder, How to activate Process builder, how to use Process builder, Launch a Flow, Launch a Flow from Process builder, Lightning Flow, Lightning Flow Dynamic Approval, Lightning Flow example, lightning flows in salesforce, Lightning Process builder, New Flow, PB, Process Builder, Process Builder and Approval process, Process Builder example, Process Builder examples, Process Builder Salesforce, Process builder use case, Record lookup in flow, Record Update element in Flow, sales force automation software, salesforce Admin exam, salesforce automation, salesforce automation tools, salesforce certified developer exam, Salesforce Certified Sales Cloud Consultant, Salesforce Flow, Salesforce Flow Example, salesforce flows, salesforce lightning flow, salesforce lightning flow examples, Salesforce release exam, Send approval request to queue, Static Approval process
    • Getting Started with Salesforce Flow – Part 44 (Auto Convert Marketing Qualified Leads)

      Posted at 9:13 PM by Rakesh Gupta, on December 1, 2020

      Big Idea or Enduring Question:

      How do you set automation to auto-convert marketing qualified leads? 

      When there is a chance of further negotiations with a lead, it can be converted into an account, contact, optionally an opportunity. In short, once the lead status has reached a certain stage, it can be qualified as a potential. On conversion, all the lead details are transferred in creating an account, contact, and optionally an opportunity. The lead conversion process is a manual process, if you want to automate it then you have to use Apex code. This article will help you to understand how to automate the lead conversion process using the Lightning Flow. 

      Objectives:

      After reading this blog post, the reader will be able to:

      • Use After-save Record-Triggered Flow to auto-convert marketing qualified leads 
      • Understand @InvocableMethod Annotation
      • Use Schedule-Triggered Flow to call an Apex method

      Business Use Case

      Pamela Kline is working as a System administrator in Universal Container. She has received a requirement from the management to auto-convert marketing qualified  (i.e. leads with Rating = Hot) leads and create an account and contact record.

      Automation Champion Approach (I-do):

      While this can be solved using various automation tools like Apex or Process Builder and Apex, we will use After-save Record-Triggered Flow and call an Apex method. To call an Apex method, add the Call Action element to your flow and select an Apex class with a @InvocableMethod Annotation. It means they allow us to extend the Lightning Flow by writing Apex code that meets certain criteria and then invoking the Apex from our Flows. If the class contains one or more invocable variables, manually enter values or reference field values from a related record. @InvocableMethod Annotation supports bulk operations. Let’s begin the solution for the business use case.
       
      In this article, we will use the call LeadConvert database class from Apex code. Make sure to review it. 
       
      Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
       

      Let’s begin building this automation process.

      Guided Practice (We-do):

      There are 2 steps to solve Pamela’s business requirement using Lightning Flow. We must: 

      1. Create an Apex class and test class
      2. Lightning Flow Steps:
        1. Define flow properties for record-triggered flow
        2. Adding an action to Call an Apex Class

      Step 1: Create an Apex class and Test class   

      1. Click Setup.
      2. In the Quick Find box, type Apex Classes.
      3. Clicks on the New button.
      4. Copy code from GitHub and paste it into your Apex Class. 
      5. Click Save.

      Repeat the above steps and click the Test class. You can get the code from my GitHub repo. 

      Step 2.1: Lightning Flow – Define Flow Properties 

      1. Click Setup.
      2. In the Quick Find box, type Flows.
      3. Select Flows then click on the New Flows.
      4. Select the Record-Triggered Flow option and click on Next and configure the flow as follows: 
        1. How do you want to start building: Freeform
        2. Trigger the Flow When: A record is created or Updated
        3. Run Flow: After the record is saved
        4. Object: Lead
      5. Select All Conditions Are Met (AND). 
      6. Set Conditions
        1. Row 1
          1. Field: Lead | Rating
          2. Operator: Equals 
          3. Value: Hot
      7. Choose the Option to Only when a record is updated to meet the condition requirements.
      8. Click Done.

      Step 2.2: Lightning Flow – Call an Apex Class

      The next step is to call the AutoConvertLeads class from flow so that when flow fires it auto-convert the leads.

      1. Under Toolbox, select Element. 
      2. Drag-and-drop Action element onto the Flow designer. 
      3. In the Action box, type AutoConvertLeads.
      4. Clicks on the AutoConvertLeads apex class. 
      5. Enter a name in the Label field; the API Name will auto-populate.
      6. Set Input Values: 
        1. Row 1:
          1. LeadIs: {!$Record.Id}
      7. Click Done.

      In the end, Steven’s Flow will look like the following screenshot: Once everything looks good, perform the below steps: 

      1. Click Save.
      2. Enter Flow Label the API Name will auto-populate.
      3. Click Show Advanced.
      4. Type: Record-Triggered Flow
      5. API Version for Running the Flow: 50
      6. Interview Label: Auto Convert Leads {!$Flow.CurrentDateTime}
      7. Click Save. 

      Almost there! Once everything looks good, click the Activate button.

      Proof of Concept

      Now onwards, if a business user updates the Lead Rating to Hot, Lightning Flow will automatically convert such leads and create an account as well as a contact. 

      1. Currently, the lead Gaurav Pradhan is Open and the Rating is Warm as shown in the following screenshot:
      2. Now we update the Rating to Hot and see the flow magic. 
      3. Flow auto converts the Lead and create an Account and Contact or it.

      Note: –  I will suggest you implement this first in your developer org, test it and then move it to production. The same approach will work for the case assignment rule. Download Apex and Test class from GitHub. 

      Process Builder Approach

      Formative Assessment:

      I want to hear from you!  

      What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? 

      Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

      Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

      Posted in Apex, Process Builder, Sales cloud, Salesforce Flow | 99 Comments | Tagged Activate a Process, Add action Process Builder, Add Criteria Proces builder, ADM 201, adm 201 certification, adm 201 salesforce, After-save flow After save flow, Auto convert Lead, Auto convert Lead in Salesforce, Auto convert Lead using Apex, Auto convert Lead using Apex Trigger, Auto convert Lead using PB, Auto convert Lead using Process, Auto convert Lead using Process Builder, Auto Convert Leads, Auto Convert Leads Apex trigger, Auto Convert Leads Automation Champion, Auto Convert Leads in Salesforce, Auto Convert Leads in Salesforce using APex, Auto Convert Leads in Salesforce using Apex Trigger, Auto Convert Leads in Salesforce using Process Builder, Auto Convert Leads process, Auto Convert Leads Process Builder, Auto Convert Leads process in Salesforce, Auto Convert Leads process in Salesforce codeAuto Convert Leads process in Salesforce code, Auto Convert Leads process in Salesforce Proces, Auto Convert Leads process in Salesforce Process, Auto Convert Leads Rakesh Gupta, Auto Convert Leads Salesforce, Automation Champion, flow, flow builder in salesforce, flow builders, Lightning Flow, lightning flows in salesforce, Lightning Process builder, Platform App Builder, Platform App Builder Exam, Process Builder, Process Builder examples, Process Builder rakesh, Process Builder Sales Cloud, Process Builder Salesforce, Process Builder Service Cloud, Process builder use case, Process Criteria, Process management, sales force automation software, salesforce, salesforce Admin exam, salesforce automation, salesforce automation tools, salesforce certified developer exam, salesforce flows, salesforce lightning flow, salesforce lightning flow examples, Salesforce Online Training, Salesforce Platform Developer I, Salesforce Platform Developer I Exam, Salesforce Training, when a record is created or edited
    ← Older posts
    • Search

    • Upcoming Trainings

      Salesforce Administrator Certification
      Salesforce Advanced Administrator Certification
      Salesforce Platform App Builder Certification
      Lightning Flow & Process Builder
      Pardot Specialist & Consultant Certification
      Sales Cloud Consultant Certification
      Service Cloud Consultant Certification
      Community Cloud Consultant Certification
    • Sponsor #1

    • Sponsor #2

    • Sponsor #3

    • Sponsor #4

    • Order Now!

    • Buy My Book

    • Buy My Book

    • Recent Posts

      • Getting Started with Salesforce Flow – Part 55 (Add or Remove Followers to a Record with the Help of Salesforce Flow)
      • Getting Started with Salesforce Flow – Part 54 (Auto-follow a Chatter Question After Reply)
      • Getting Started with Salesforce Flow – Part 53 (Clone a User with their associated Public Group, Queue Membership and Permission Sets)
      • Getting Started with Pardot – Part 14 (How to Use Pardot Form Handlers)
      • Getting Started with Salesforce Flow – Part 51 (Add a Flow to a Lightning Page)
    • Salesforce ID Converter Build on Lightning Flow

      Converting 15 digit ID to 18 digit Salesforce ID
    • Blog Archives

    • Categories

  • Information

    • About Me
    • Affiliate Disclaimer
    • Contact Me
    • Privacy Policy
  • Top Posts

    • Salesforce Spring’21 Release Quick Summary
    • Learning Flow
    • Getting Started with Salesforce Flow – Part 53 (Clone a User with their associated Public Group, Queue Membership and Permission Sets)
    • Learning Process Builder
    • Getting Started with Salesforce Flow – Part 55 (Add or Remove Followers to a Record with the Help of Salesforce Flow)
    • Getting Started with Salesforce Flow – Part 11 (Count Number of records in a Record Collection Variable)
    • Getting Started with Salesforce Flow – Part 31 (Auto Submit Record into Approval Process with Flow)
    • About Me
    • Getting Started with Salesforce Flow – Part 33 (Prior Value of a Record in Record-Triggered Flows)
    • Getting Started with Salesforce Flow – Part 24 (Automatically Assign Permission Sets to New User)
  • Social Media

    • View Automationchampion’s profile on Facebook
    • View Automationchamp’s profile on Twitter
    • View Rakeshistom’s profile on GitHub