Skip to main content
Hi Folks,

 

How to create validation rule which should validate country based on Phone Country code. 

 

Ex:  If phone number starts  with +91 in phone field then it should select country as india.

 

similary for rest of the countries this should be validate.

 

Can anyone help me on this ??
1 answer
  1. Apr 9, 2019, 11:19 PM
    Hi PRATHAP SF,

     

    This requirement is not possible with using standard validation rule, but its quickly achievable using customizations (using apex trigger validation) and below are quick steps to achieve.

     

    1) Create a metadata to capture all your country information and along with relevant Phone Country Code

     

    2) Create a Apex Trigger (before insert, before update) to check the user entered phone country code to check respective country code and country information is matched or not from defined metadata, if not then add the error message from trigger.

     

    some reference to use metadata type and validation error in apex triggers:

     

    https://salesforce.stackexchange.com/questions/152103/need-help-on-custom-metadata-type

     

    https://medium.com/@krissparks/apex-triggers-for-custom-validations-fcac30c76281

     

    https://andyinthecloud.com/2015/04/19/considerations-placing-validation-code-in-an-apex-triggers/

     

    Thanks & Regards,

     

    Sakthivel Madesh