A flow is the part of Salesforce Flow that collects data and performs actions in your Salesforce org or an external system. Nowadays flows are superseding across all other automations in Salesforce. Flows come with great flexibility and ability to perform many operations including the autolaunching ability to be able to run independently on some triggering event. To know more on flows and their types please click here.
Since our main focus is on how to authenticate a user using OTP, let's concentrate on that. Though salesforce provides inbuilt mechanism to cater for the OTP authentication for its internal and external users using Salesforce MFA, there might be scenarios where we are neither Salesforce internal nor external users. Simply saying, what if we have a portal/public community where the users come, here users refer to person accounts/contacts in salesforce, and if we want to authenticate the end users identity by sending and capturing the OTP. This verification can be of two types:
- OTP verification using SMS
- OTP verification using Email
-
Create an Apex Class named OTPGenerator: This class implements
the Process.Plugin interface which makes
OTPGenerator visible to flows action.
public class OTPGenerator implements Process.Plugin { public Process.PluginResult invoke(Process.PluginRequest request){ Map<String, Object> result = new Map<String, Object>(); String randomIntegerString = string.valueof(Math.abs(Crypto.getRandomInteger())); String otp = randomIntegerString.substring(0,6); result.put('OTP', otp); return new Process.PluginResult(result); } public Process.PluginDescribeResult describe() { Process.PluginDescribeResult result = new Process.PluginDescribeResult(); result.description = 'This plug-in generates a radnom 6-digits code'; result.tag = 'Identity'; result.inputParameters = new List<Process.PluginDescribeResult.InputParameter> {}; result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter> { new Process.PluginDescribeResult.OutputParameter('OTP', Process.PluginDescribeResult.ParameterType.STRING) }; return result; } }
- Create an Autolaunched Flow:
- Select Freeform style and this will open the flow builder canvas. Go to Manager as shown below
- Create two new resources recordId and OTP as shown below
- Now go to Elements and drag-drop Get Records on the flow builder canvas and complete the mandatory fields.
- Label: Get Contact Record
- Object: Contact
-
Filter Condition: Id equals recordId
- Drag-drop the Action from Elements to flow builder canvas to generate and store the OTP
- Filter By: Type
- Apex Action(Legacy)
- Action: OTPGenerator
- Label: Generate OTP for verification
- Store Output Values: OTP
- Drag-drop Action again on the flow builder canvas and select following to send the generated OTP via mail.
If you like this blog content and find inciteful, please comment and let me know.
It's really helpful
ReplyDeleteBlog is too good.
ReplyDeleteHi, do you have implementation of OTP verification using SMS?
DeleteHi, do you have implementation of OTP verification using SMS?
ReplyDelete