Carry out the following steps to create a validation rule to enforce the entry of a standard two-letter country code on an account record:
- Click on the Setup gear icon in the top right-hand corner of the main Home page, as shown in the following screenshot:
- Click on Setup as shown in the following screenshot:
- Navigate to the Account Validations Rule setup page by clicking the following: Objects and Fields | Object Manager | Account | Validation Rules.
Locate the Validation Rules section on the right of the page.
- Click on New.
You will be presented with the Account Validation Rule Edit page.
- Type Valid Embargo in the Field Label textbox.
Upon clicking out of the textbox, the name changes to Valid_Embargo.
- Leave the Active checkbox set.
- Optionally, enter details in the Description field.
Locate the Error Condition Formula section positioned lower down on the page.
- Paste in, or enter, the following code:
VLOOKUP( $ObjectType.Country_Code__c.Fields.IsEmbargo__c, $ObjectType.Country_Code__c.Fields.Name, LEFT(BillingCountry,2) )
- In the Error Message section, enter the text: This Country is on the embargoed country list.
- For the Error Location option, select Field.
You will be presented with the Field selection pick list.
- Select the field, Billing Country.
- Finally, click on Save, as shown in the following screenshot: