function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
William BlandWilliam Bland 

Best way to move forward with search for country by phone number

Hi, 

I have tried and I am unable to find a way. I have a list of country phone codes and the country. For example +44 = United Kingdom.

I had written a workflow rule, however due to limitations it ended up being around 10k characters and it is too large for the workflow. Is there a way to do this using an apex trigger and if so would someone be able to help me with the structure? 

It would need to search in a list the country code and populate a country field with the respective country. 

CharuDuttCharuDutt
Hii Willliam
Try Below Validation
IF(ISPICKVAL( Country__c , 'USA') && NOT(ISBLANK( Phone__c )) &&NOT(REGEX(Phone__c ,"[+1]{2}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL( Country__c ,'India') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+91]{3}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL(Country__c,'UK') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+44]{3}[1-9]{1}[0-9]{9}")),
TRUE,
IF(ISPICKVAL(Country__c,'Australia') && NOT(ISBLANK(Phone__c )) && NOT(REGEX(Phone__c ,"[+61]{3}[1-9]{1}[0-9]{9}")), TRUE,
FALSE)))



------------------------------------------------------------


IF(ISPICKVAL(Country__c, 'India'), AND(Not(ISBLANK(Phone)),LEFT( Phone__c , 3) <> '+91'), 
IF(ISPICKVAL(Country__c, 'USA'), AND(Not(ISBLANK(Phone)),LEFT( Phone__c  , 2) <> '+1'), 
IF(ISPICKVAL(Country__c, 'UK '), AND(Not(ISBLANK(Phone)),LEFT( PhoPhone__c ne , 3) <> '+44'), 
IF(ISPICKVAL(Country__c, 'Australia'), AND(Not(ISBLANK(Phone)),LEFT( Phone__c , 3) <> '+61'),false) ) 
) )
Please Mark it As Best Answer If It Helps
Thank You! 

 
Suraj Tripathi 47Suraj Tripathi 47
Hi Willliam,
Greetings!

If you are trying to use Apex, you can call out external services which will do this for you.
Otherwise use the regex in the formula fields

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi