Verifying Salesforce Phone Number Data using Numverify API & MuleSoft

Emilio Taylor
8 min readJun 19, 2020

Introduction

When was the last time that a user attempted to dial a phone number from Salesforce, just to find that the number provided was invalid? Or, you’ve attempted to send a text to a landline? (landline link provided for those who have no idea what that is …) What if you could confirm the validity of a phone number before it negatively impacts end-user experience and workflow in Salesforce?

In this lesson, our challenge will be to:

  • Create a Lead in Salesforce.
  • Ensure the Lead contains Phone values
  • Have the Lead tracked within MuleSoft
  • Map the Phone Validation values returned from the NumVerify API
  • Send the Lead back to Salesforce to be Updated

Prerequisites

Architecture

Salesforce: Obtain the Salesforce Security Token

In order to login to Salesforce while using MuleSoft, we need three (3) components:

  • Username
  • Password
  • Security Token

If you don’t already have a Security Token, in this lesson we will reset this token so it’s available to use when connecting to Salesforce while using MuleSoft

Steps:

  • Log in to Salesforce
  • Select the My Account icon and Select Settings
  • On the My Personal Information Page, from the left-hand menu, select Reset My Security Token
  • Check your email for the updated Security Token

Salesforce: Add Phone Verification Custom Fields

Steps:

  • Log in to Salesforce as a System Administrator
  • Select the Gear icon and select the Setup button
  • On the Setup page, select the Object Manager tab (in Lightning Experience)
  • Select the Lead object
  • On the Lead page, select Field & Relationships
  • On the Field & Relationships page, select the New button
  • On the New Custom Field, add the following Custom Fields
  • Phone_Valid__c : Data Type = Checkbox
  • Local_Format__c : Data Type = Text (100)
  • International_Format__c : Data Type = Text (100)
  • Country_Prefix__c : Data Type = Text (100)
  • Country_Code__c : Data Type = Text (10)
  • Location__c : Data Type = Text (100)
  • Carrier__c : Data Type = Text (100)
  • Line_Type__c : Data Type = Text (100)
  • Once done, add Custom Fields to Layout for users to access

MuleSoft: Creating an Application

This is the first step to creating a new application in MuleSoft.

Steps:

  • Go to the Anypoint Platform
  • On the Anypoint Platform homepage, select Start designing under the Design Center section
  • On the Projects page, select the Create New button in the upper-right hand corner
  • On the next menu in order to create an integration using a drag & drop interface, choose the Create new application button
  • On the New Mule Application screen, provide a Project name.
  • Example: GeneralSalesforceUpdate, then click the Create button
  • On the Let’s get started page, select Go straight to canvas.

Note: This will allow us to choose the trigger and output we need and not include anything unnecessary.

MuleSoft: Select Salesforce Connector: On New Object component

This step will create a connector to Salesforce. We’ll also specify which Object will be monitored for changes

Steps:

  • On the New Flow page, select the Trigger None Selected component
  • On the Trigger page, look for the Salesforce Connector
  • On the Salesforce Connector page, choose On New Object
  • On the Salesforce Configuration Page, select Add Connection
  • On the Configure Connection page, provide the following
  • On the Salesforce Connector: On New Object page, provide the following:
  • Object Type = Lead
  • Once done, select the [X] to close the Salesforce Connector

MuleSoft: Select the Set Variable for Salesforce ID component

This step might not always be necessary, but since we want to update the original Salesforce ID further down the process, we want to make sure we hold a copy in the Flow in order to do so. We also perform this step just in case we have any other processes which have an ID value that could potentially overwrite the Salesforce ID we’ve retrieved.

Steps:

  • Select the [+] next to the Salesforce Connector
  • On the Select a component page, search for Set Variable
  • On the Set Variable page, provide the following:
  • Variable Name: salesforce_id
  • Value: Drag & Drop the payload[“Id”]
  • Once done, click the [X] to close the Set Variable component

Note: If you don’t initially see the Payload section, start typing payload[“Id”] into the Value section. MuleSoft will start to populate the payload of the Salesforce record on the right-hand side.

MuleSoft: Select the HTTP Request component

This component allows us to authenticate with the API, pass parameters from Leads and return verified address information

Steps:

  • Select the [+] next to the Set Variable component
  • On the Select a component page, search for HTTP Request
payload
  • Query Parameters (Add) = access_key (provided by NumVerify)
  • Query Parameters (Add) = number (value is below)
  • Once done, click the [X] to close the HTTP Request component

MuleSoft: Select the Transform (DataWeave) component

This is the component where we tell MuleSoft that we’d like to change the data currently flowing in the process. The first time we set up the Transform, we’ll add to the flow, and return on a second pass to complete the mapping.

Note: We do this so the Transform can get connected to the potential destination so it knows what the expected output should look like. This should make the mapping process easier on future steps.

Steps:

  • Select the [+] next to the HTTP Request component
  • On the Select a component page, select Transform
  • On the Transform page, select the [X] to close the component

MuleSoft: Select the Salesforce Connector: Update component

This is the step where we define which object will be updated in this MuleSoft application. We’ll connect to the Salesforce Contact object and perform an Update

Steps:

  • Select the [+] next to the Transform component
  • On the Select a component page, select the Salesforce Connector
  • On the Salesforce Connector > Select an operation page, select Update
  • On the Salesforce Connector: Update page, provide the following
  • Type = Lead
  • On the Salesforce Connector: Update page, select the [X] to close this component

MuleSoft: Update the Transform (DataWeave)

We will now return to the Transform mapping to map the values we’d like to update. This is where we pass the values we receive from the NumVerify API back to Salesforce to be updated

Steps:

  • Select the Transform component
  • On the Transform page, select the Script tab towards the bottom
  • On the script tab, copy & paste the following script
%dw 2.0output application/java---[   {     Id: vars.Salesforce_Id,     Phone_Valid__c: payload.valid,     Local_Format__c: payload.local_format,     International_Format__c: payload.international_format,     Country_Prefix__c: payload.country_prefix,     Country_Code__c: payload.country_code,     Location__c: payload.location,     Carrier__c: payload.carrier,     Line_Type__c: payload.line_type   }]
  • On the Transform page, select the [X] to close the component

MuleSoft: The Completed Flow

MuleSoft: Test your application

Now that everything is connected, we’ll need to test the process. We’ll log in to Salesforce, open a Contact record, edit the record and watch that the Description is updated to Hello World.

Steps:

  • While in MuleSoft, select the Test button in the upper-right corner
  • Create a New Lead Record
  • Make sure Phone is populated (note: leave off the leading “1”)
  • Save the Lead Record
  • On Refresh, see that the County, Congressional District values are updated

What’s Next?

Bad phone numbers are No Bueno! Get your data in gear and present your users with accurate information to engage customers. I encourage you to learn more. Here’s what I recommend:

--

--

Emilio Taylor

Salesforce Practice Leader, Technology Enthusiast, Entrepreneur, Integrator, Architect, Developer, and Overall Cloud Advocate.