Home SalesforceApex Verify Phone in Salesforce using VeriPhone API

Verify Phone in Salesforce using VeriPhone API

by Dhanik Lal Sahni
Phone-Verification-in-Salesforce

Verified phone is required by many clients for their business use case. Verified phone helps business to give their services to valid customers. Below are some reason where business are going with phone verification

  • Better Service : If phone (mobile) is verified then we can send service messages on mobile. Instead of sending message on fake mobile number it will reach to correct person.
  • Avoid Fake : Fake profile can be created by users. Phone verification will help us to take decision for deleting, deactivating or activating them.
  • Easy Use: SMS/Message are preferred way for notification of any service update. So phone verification is required.

In Salesforce we can easily validate mobile/phone number using regular expression but system will not help in verification of phone number.

There are many API/products available for phone verification. Here are some API which can do phone verification

  1. Twilio
  2. Veriphone
  3. Telesign
  4. Nexmo

I am using Veriphone for verifying phone in this post but we can use any one based on license availability.

Use Case:

Account object is storing customer information. We need to verify object record’s phone number.

Solution:

We can verify all account records in one go with batch processing or we can go manually one by one for phone verification. I am going with manual verification.

Step for this use case solution:

  1. Veriphone API integration
  2. Flow creation to call apex
  3. Add button on screen
  4. Testing solution

1. Veriphone API integration:

Before we use Veriphone API , we have to create a free account at here. Once you create and verify account. Go to setting page of your API dashboard and copy API key.

As we have API key now to call veriphone api. Let us create a basic apex class to call this API. We can use this API using GET/POST call. I have used GET method of this API to verify it. This API required only phone number with country code and API key.

API Url : https://api.veriphone.io/v2/verify?phone=mobile&key=apikey

Replace mobile and API key based on your setting and record page.

Apex Class:

2. Flow Creation to call above Apex

We have to call above class method from flow to get verification done. So for doing this we need InvocableMethod which can be called from flow.

Let us create a controller class to call above phone service class.

Now we need to create a flow to call this method.

Verify Phone in Salesforce

Flow Type : Screen Flow

Element used : Get, Update, Decision, Screen, Action and Assignment

Flow Steps:

  1. Create a variable recordId of text type to get current record id
  2. Use Get element to get account record based on above recordId. Return mobile/phone and PhoneVerified fields. Phone Verified field is custom boolean field to store status of verification.
  3. Add Action element and use above created action Verify Phone (PhoneVerificationController). Pass account record phone field to method. Add one variable to store boolean response from action call.
  4. Check response value using decision element. If returned value is true then assign true to Phone Verified field and update record using Update element.
  5. If response is false then simply show message that phone is not verified.

If you are able to do this step properly then clap for your self, if not then use flow metadata from here.

3. Add button on Page layout

We need button on account page layout so that we can verify phone. For this let us create a new action button and call above flow from that button.

Verify Phone in Salesforce

After button creation add that button to page layout in Salesforce Mobile and Lightning Experience Actions section.

Test page:

References:

https://veriphone.io/docs/v2

You may also like

4 comments

Ankita June 5, 2021 - 11:09 pm

Very useful….

Reply
Dhanik Lal Sahni June 6, 2021 - 1:11 am

Thank You @Ankita

Reply
Asim Rahim May 21, 2023 - 4:05 am

Hi Dhanik, first, I would like to thank you for sharing this article, and it’s really helpful. i tried creating a flow and getting this error when debugging the flow. “Error Occurred: The flow tried to update these records: 001Hs00002nWJk9IAG. This error occurred: INVALID_TYPE_ON_FIELD_IN_RECORD: PhoneVerified: value not of required type:
I used check box data type for PhoneVerified field.

Reply
Dhanik Lal Sahni May 22, 2023 - 8:13 pm

Hello Asim,
Looks like your are not getting API result in boolean. Please try to debug data and data type before assigning to PhoneVerified field.

Thank Yoi,
Dhanik

Reply

Leave a Comment