Problem statement - The customer was initially sending SMS to a specific country (example - the USA with country code 1). Now they want to send SMS to multiple countries and hence the SMS Magic country setting needs to be changed to All.


Solution -  For the incoming SMS to be correctly associated with the related records(leads/contacts, etc), we require the mobile numbers to be stored in plain format without any special characters and with the country code as prefix ( example - 1xxxxxxxxxx for the USA)


You can create a new formula field on your object and insert the following code, this will remove special characters like - "(", ")", "-", ".", "+" and insert 1 as the prefix. You can replace "1" from the formula mentioned below with any country code.


Examples of some formats that can be corrected using the formula - 

(xxx) xxx-xxxx, +1 (xxx) xxx-xxxx, +33 (xxx) xxx-xxxx, +1.xxx.xxx.xxxx, xxx-xxx-xxxx, (xxx) (xxx) (xxxx), etc.


To create a formula field, following are the steps - 

  • Go to Setup
  • Now go to the object for which the field needs to be created
  • Go to Fields and relationship
  • Create a new field
  • Select field type as Formula
  • Select the data type as text
  • Paste the formula mentioned below
  • Replace MobilePhone with the API name of the field where you store your mobile numbers
  • Save


IF( LEN(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE( MobilePhone , "(", ""), ")", ""), " ", ""), "-", ""), ".", ""), "+", "")) = 10 ,


"1" &

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE( MobilePhone , "(", ""), ")", ""), " ", ""), "-", ""), ".", ""), "+", ""),


SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE(

SUBSTITUTE( MobilePhone , "(", ""), ")", ""), " ", ""), "-", ""), ".", ""), "+", ""))





Once the field is created, you need to create incoming lookup settings so that the incoming SMS checks the new field for the lookup.

You can follow the steps mentioned here for the same.