Accuracy of phone numbers is essential to any business for effective communication with customers. HTTP Callout is a feature in the Salesforce Flow to call external API without code.
VeriPhone API is a REST-based JSON API that can validate, format, and locate any phone number.
Steps for implementing and integrating VeriPhone API
Setup User in VeriPhone API
Create a Permission Set for Callout
Create an External Credential and a Named Credential
Create Salesforce Flow to Verify Phone/Mobile
Add button
Test Flow
Let us implement all these steps one by one
1. Setup User in VeriPhone API
Create a free user in the VeriPhone system (https://veriphone.io). You can use your Gmail or GitHub user to create a free account.
Once registration is done, verify the account using the confirmation link. A confirmation email will be sent to the email which is used for registration. After confirmation, you can see your API key detail in the Settings section
Now copy the API key, In the next step, we can use it.
2. Create a Permission Set for Callout :
Login into your Salesforce developer account.
Create a permission set Callout User PS and assign this permission set to yourself. This permission set will be assigned to all users who need to call external API using flow. You can create a permission set from Setup -> Permission Sets ->New
Assign object permission (CRUD) “User External Credentials” to store encrypted tokens used by named credentials.
3. Create an External Credential and a Named Credential:
We will create a named credential to call external API. We will create external credentials first before creating named credentials.
An external credential represents the details of how Salesforce authenticates to an external system via an authentication protocol. So, we have an API key that is passed in the URL to authenticate callout so we will use a custom authentication protocol.
You can create a Named credential from Setup->Named Credential->select External Credential Tab -> New
Once we set the authentication protocol, set permission set mapping which will indicate who all users can call named credentials.
Put base API URL in Url property for named credential. If we have an API Url
then only put https://api.veriphone.io and the rest of the URL will be appended using the Http Callput action. Add the above-created external credential to the External Credential property.
4. Create Salesforce Flow to Verify Phone/Mobile
Now let us create a screen flow Verify Phone that will validate the customer’s phone number and update the verification status in the Patient record.
i. Get Current Record
Create a recordId property of the Patient record type. We will get the current Custom Object record in this property. recordid is a dynamic variable that can hold record id as well as Custom Object
ii. Create a dynamic Action
Now drag an Action element on the screen element. You will get + Create HTTP Callout in the action selection dialog. We will get New HTTP Callout screen to create a callout in flow
Put the required information in the HTTP Callout screen.
(1) API URL path. This will be appended to the base named credential Url that is set in the named credential.
(2) Required Url parameters. Values for these parameters are replaced using Flow variables.
(3) Provide Sample response JSON to create response Apex Class automatically.
Provide sample response JSON by clicking on Add/Edit in Provide Sample Response section. This will create a response apex wrapper class.
This process will create an external service VeriPhoneES that can be checked using Setup->External Services. It will also create a dynamic apex response class.
iii. Create a Response Object
Let us create an element that will store the response after the HTTP callout action is performed. That response object will be used to get the status of phone verification
iv. Call API using Dynamic External Service
Call dynamic external service in flow that was created after HTTP Callout action was created. As per API, we have to pass the API key and Phone number that need to verify. The response is saved in the above-created response object.
The API key can be saved in custom settings/custom metadata and can be populated from there. I have hardcoded it for demo purpose
v. Update Phone Verification using Update Element
Based on the response object update the status of the current patient record phone verification.
Create a formula field to display the verification message and highlight in a different color based on phone number is valid or invalid
vi. Complete Flow
5. Add button on Page layout
We need to display a button on the Patient page layout so that we can verify the phone. For this let us create a new action button and call the above flow from that button.
After button creation add that button to the page layout in the Salesforce Mobile and Lightning Experience Actions section.
6. Test Flow
Now everything is set up. Let us Test any Patient record where a phone number is entered. Click on the button “Verify Phone” and check the verification status
Conclusion:
By leveraging Salesforce Flow and external APIs, you can automate the process of phone number verification without writing any code.
In this blog, we have verified the phone number with a click of a button which will avoid unnecessary API calls and also provide flexibility for users to verify the phone numbers as needed.
You can also configure the flow to automatically verify the phone number when the record is created or updated using the record trigger flow.
Comments