Skip to main content

How to Enforce Customer ID Format ?

 Business Requirements: 

Each customer should have one customer Id in particular format and unique so that It can be sync other systems. Some customers may not have customer Id. If user add any customer information and enter customer Id then enforce that the customer ID should include the 2-character billing country code, a dash, and an 8-digit number (for example, US-12345678). Each customer ID must be exactly 11 characters in length with zero spaces.

Solution:

1. Create a custom field on Account which is Text Type (length 11) and unique.

2. Create formula field Billing_Country_Code__c to get country code from Account address.

Billing_Country_Code__C = TEXT(BillingCountryCode)

3. Write Validation rule 

Customer_ID_Format 
 
AND(
    NOT(ISBLANK(Customer_ID__c)),
OR((LEFT(Customer_ID__c , 2) != Billing_Country_Code__c ),
NOT(REGEX(Customer_ID__c, "^[A-Z]{2}-\\d{8}$"))
  )

    
 )

(LEFT(Customer_ID__c , 2) != Billing_Country_Code__c - Checking if user entering correct country code or not.

Error Message : Please add customer Id in proper format.'XX-NNNNNNNN' where X is the 2-character billing country code and N is an 8-digit number.


Comments