Enable Validation Rules¶
Overview¶
Validation checks an address against the AddressTools reference data before the record is allowed to save. It can require the fields you consider essential, and reject a country, state or ZIP code that does not exist in the data installed in your org.
Validation is configured in three layers, and this guide follows them in order:
- The Country record holds what each rule requires for that country, for example whether a state is mandatory in the United States.
- The address block chooses which of those rules apply to a given address, so a billing address can be stricter than a shipping address on the same object.
- One org-wide setting turns validation on.
A rule only takes effect when all three are set.
Available Rules¶
Two rules apply to the country field itself, and are set in the Global Settings section of an address block:
- Country Mandatory requires a country before the record can be saved.
- Allow Only Listed Countries rejects any country that is not an installed Country record.
The rest are country-specific, and are set in the Country-Specific Settings section of the block:
- Street 1 Mandatory, City Mandatory, State Mandatory and ZIP Code Mandatory each require that field.
- Allow Only Listed States rejects any state that is not an installed State record for that country.
- Validate Postal Code Against Regex checks the postal code against the pattern held on the Country record.
Two more apply to the United States only:
- Allow Only Listed ZIP Codes rejects a ZIP code that is not in the installed US ZIP Code data.
- Enable City and State Validation Against US ZIP Code checks that the city, state and ZIP code are a valid combination.
Both US rules read the US ZIP code reference data, which is an optional selection in the data installation and is not installed by default. See Install Country Data.
Step 1: Configure the Rules per Country¶
The Country records are the base of the configuration. They hold what each rule requires for a given country, and an address block then chooses which of those rules to apply.
The per-country values are fields on the Country records. Country-Specific Settings in AddressTools Administration provides direct access to them: each Configure button opens a Country list view filtered to the fields for one group of settings, so you can set the same rule across several countries from a single screen.
Note: These settings are fields on the Country record, so you can also open a country from the Countries tab and edit them there. The list views are quicker when you are setting one rule across several countries; the record is easier when you are configuring a single country fully.
- In AddressTools Administration, select Country-Specific Settings from the left menu.
-
Click Configure beneath the group holding the setting you want to change:
- Allowed Values opens a list view showing Visible and Allow only listed States.
-
Mandatory Fields opens a list view showing Street Line 1 is Mandatory, Street Line 2 is Mandatory, City is Mandatory, State is Mandatory and ZIP Code is mandatory.
Note: The address block has no Street 2 Mandatory checkbox, so Street Line 2 is Mandatory on the Country record has no effect unless the matching setting is enabled on the block through its View Custom Setting row action.
-
Validate ZIP Code Pattern opens a list view showing Validate ZIP Code, ZIP Code Regular Expression and ZIP Code pattern fail message.
- Edit the values against each country you want the rule to apply to, then click Save.
Note: Requirements differ by country which is why these are optional. For example, a US address requires a state postally, whereas a UK address has no state requirements, so State is Mandatory does not apply there. The installed data already reflects that difference, so check the value on the Country record before changing it.
Step 2: Choose the Rules for an Address Block¶
With the countries configured, the address block decides which of those rules apply to the address it maps.
- Click the App Launcher to search for and select AddressTools Administration.
- Select Address Blocks from the left menu.
- Open the block for the address you want to validate by using the dropdown to select Edit.
- In Global Settings, select Country Mandatory and Allow Only Listed Countries as required.
- In Country-Specific Settings, select the country rules you want applied for this address.
- Click Save.
Repeat for each address block you want validated. Rules are per block, so a billing address can be stricter than a shipping address on the same object.
Note: The rules in Country-Specific Settings are switches rather than values. Selecting State Mandatory on the block tells AddressTools to respect the State is Mandatory setting held on each Country record, so the rule applies only to the countries you configured it for in Step 1. Both have to be set before a rule takes effect.
Step 3: Turn Validation On for Your Org¶
- In AddressTools Administration, select Settings from the left menu.
- In the Feature Enablement section, click the pencil icon beside Validation Enabled.
- Select the checkbox, then click Save.
This is the master switch for validation. The rules configured above only take effect once it is on.
When a Rule Fails¶
When a rule fails, the save is blocked and Salesforce shows the error against the record. For a postal code pattern the message is the one you entered in ZIP Code pattern fail message, so make it specific enough to act on.
Validation runs through the object's trigger, so it applies however the record is saved, including through the API and data loads. See Activate Triggers.
Note: Validation checks an address against the AddressTools reference data. It does not confirm that the address exists. For that, see Verification.