How to Generate OTP Using Salesforce Flows?

on

|

views

and

comments

Introduction

As we all know that Salesforce is forcing the 2-Factor Authentication for all the Salesforce Orgs. Where you must need to verify your identity either using some external devices with the help of some code or using Salesforce Authenticator application.

On-Top of that if you want to add the extra layer of security we can do that with the help of Salesforce Login flows where we can ask users to verify email, phone or other sensitive information.

In this blog post, we will see we can generate the OTP and then use the same in our Login Flow for further blog posts.

Generating the OTP and using it as a second factor of authentication is very important these days. We will see how we can generate the OTP using flow.

Create OTP Object

To store the OTP information for all the users, we will be creating our own custom object. Create the custom object with the following fields.

  1. Login to Salesforce
  2. Navigate to Setup –> Object Manager
  3.  Click on Create -> Custom Object

Create the following fields by referring the following screenshot.

For formula fields here is what we have

  1. Expired__c : NOW() > amit__ExpireTime__c
  2. Username__c : amit__User__r.Username
  3. ExpiredDateTime__c : ( amit__GeneratedDateTime__c +(15/1440) )

Create Custom object Tab

Once You have created the OTP object also create the custom tab for the same. Follow the steps from the below link

https://help.salesforce.com/s/articleView?id=sf.creating_custom_object_tabs.htm&type=5

Create Apex Class

Once you have created the custom tab. Now the time is to Create the Apex Class which will generate the OTP and return to the flow record.

Develop the flow

After, we have developed the Apex Class Now the time is to develop the Lightning Flow Builder.

Follow the below steps to create the flows.

  1. Navigate to Setup –> Flows -> Click on “New Flow” button
  2. Select Record Triggered Flow from the type of flows

Add Resource in Flow

Click on the “New Resource”. from the left hand side and create a variable of type “OTP__c”

Add Action in flow

Click on the + Icon and the select Action, From the Search bar Search for Generate OTP and select the custom invocable apex action that you have created as part of custom Apex Class.

Add assignment in flow

Again click on the + Icon and then select the Assignment element.

Prepare the assignment using the below screen. We need to assign the below variables

  1. OTP which we have got from the Apex Action
  2. Status as Generated 
  3. Also, we need to map the Record Id so that we can update the OTP Record

Add update record

Now, as we have got the OTP, prepared the assignment. We need to update our OTP record so that we can update the unique code to our OTP record against each user

Click on + Icon and select Update Records element. 

 

Save and test flow

Once you have developed the flow. It will look like below screenshot.

 

To test the flow, go to the app launcher. Find OTP Tab and then Create a new record. 

Note:- Please do not put anything for OTP (Text) field.

 

Complete video

Thanks for reading! If you have any questions, please post into the comment section.

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

Recent articles

More like this

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential