Validation Rule Setup
Prerequisites
-
To set up validation rules, you need:
-
Minimum permissions for the FieldFX modules you are using
-
System permissions:
-
API Enabled
-
Author Apex
-
Customize Application
-
View Setup and Configuration
-
-
How it Works
Validation rules run:
When you save a record: | When you change the status of a record: |
---|---|
|
|
You can add validation rules for use in:
-
FieldFX Back Office only
-
FieldFX Mobile only
FieldFX Mobile validation rules are managed in the Admin Portal’s Mobile Validations tool.
Examples
FieldFX Back Office
Validate the Input Qty field on the Ticket Item object.
( ( (FX5__Input_Qty__c < NULLVALUE(FX5__PBI_Minimum_Quantity__c, 0)) && NOT(ISNULL(FX5__PBI_Minimum_Quantity__c))) || ( (FX5__Input_Qty__c > NULLVALUE( FX5__PBI_Maximum_Quantity__c, 0)) && NOT(ISNULL(FX5__PBI_Maximum_Quantity__c))) )
This rule forces users to select an Input Qty that is greater than or equal to the Minimum Quantity, and less than or equal to the Maximum Quantity.
FieldFX Mobile
Validate the Customer and Price Book lookups on the Job object.
"FX5__Job__c" : {
"QuoteValidation1": {
"fullName": "QuoteValidation1",
"errorConditionFormula": "!ISBLANK(FX5__Quote2__c) && ( ISCHANGED (FX5__CustomerAccount__c ) || ISCHANGED ( FX5__Price_Book__c ) )",
"errorMessage": "You can't change the customer or price book for jobs created from quotes."
}
}
Adding Validation Rules
FieldFX Back Office
-
Add the validation rule:
-
From Setup, enter
object
in the Quick Find box, then select Objects. -
Click Job.
-
Under Validation Rules, click New.
-
In Rule Name, enter
Projected End Date
. -
Select Active.
-
In Description, enter "Prevents an invalid Projected End Date being entered".
-
Under Error Condition Formula, enter the following formula:
FX5__Projected_Start_Date__c > FX5__Projected_End_Date__c
-
In Error Message, enter the following:
The Projected End Date must follow the Projected Start Date.
-
In Error Location, complete one of the following and click Save:
-
Select Top of Page to display validation error messages at the top of the page.
-
Select Field and "Projected End Date" to display validation error messages inline next to the Projected End Date field.
-
-
-
Test the validation rule by adding a record and entering invalid data.
A warning should display when you enter invalid data in the location you specified.
Test a validation rule thoroughly before activating it.
A poorly designed validation rule can prevent users from saving or syncing data.
FieldFX Mobile
Validation rules for FieldFX Mobile are managed in the Admin Portal’s Mobile Validations tool. You can use the Mobile Validation to add new rules, modify existing rules, and import rules from FieldFX Back Office
Scenario
This guide explains how to add a validation rule to the Price Book lookup on the Job object.
This rule forces users to select the customer’s price book when adding a job.
-
Add an FX_Mobile_Rules static resource:
-
Open a text editor.
-
Enter the following to name the static resource:
window.FX_Mobile_Rules = { "validationRules" : { } }
-
Enter the API name of the object to which the field belongs:
window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { } }}
-
You can only add validation rules for fields on the Job, Ticket, Ticket Item, and FX Form objects.
-
You can add an unlimited number of validation rules for each supported object.
-
-
Enter a name for the validation rule:
window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { "PriceBookValidation1": { "fullName": "PriceBookValidation1", } } } }
-
Enter the formula to use for the validation rule:
window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { "PriceBookValidation1": { "fullName": "PriceBookValidation1", "errorConditionFormula": "(FX5__Price_Book__r.FX5__Account__c <> FX5__CustomerAccount__c) && NOT(ISBLANK(FX5__Price_Book__r.FX5__Account__c)) && NOT(ISBLANK(FX5__CustomerAccount__c))", } } } }
-
Don’t use Roll-Up Summary fields in the formula.
-
Only use supported functions and operators in the formula.
Refer to the Formulas article for a list of supported functions and operators. -
-
Enter the name of a field so that validation error messages display inline next to that field:
window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { "PriceBookValidation1": { "fullName": "PriceBookValidation1", "errorConditionFormula": "(FX5__Price_Book__r.FX5__Account__c <> FX5__CustomerAccount__c) && NOT(ISBLANK(FX5__Price_Book__r.FX5__Account__c)) && NOT(ISBLANK(FX5__CustomerAccount__c))", "errorDisplayField": "FX5__Price_Book__c", } } } }
If you don’t specify an errorDisplayField, validation error messages display at the top of the page.
-
Enter the message to display when users enter invalid data:
window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { "PriceBookValidation1": { "fullName": "PriceBookValidation1", "errorConditionFormula": "(FX5__Price_Book__r.FX5__Account__c <> FX5__CustomerAccount__c) && NOT(ISBLANK(FX5__Price_Book__r.FX5__Account__c)) && NOT(ISBLANK(FX5__CustomerAccount__c))", "errorDisplayField": "FX5__Price_Book__c", "errorMessage": "You must select the customer's price book." } } } }
-
Add braces
{ }
to end the validation rule:window.FX_Mobile_Rules = { "validationRules" : { "FX5__Job__c" : { "PriceBookValidation1": { "fullName": "PriceBookValidation1", "errorConditionFormula": "(FX5__Price_Book__r.FX5__Account__c <> FX5__CustomerAccount__c) && NOT(ISBLANK(FX5__Price_Book__r.FX5__Account__c)) && NOT(ISBLANK(FX5__CustomerAccount__c))", "errorDisplayField": "FX5__Price_Book__c", "errorMessage": "You must select the customer's price book." } } } }
Every left brace
{
should have a matching right brace}
. -
Save the file with "FX_Mobile_Rules" as the file name.
-
-
Upload the FX_Mobile_Rules file to FieldFX Back Office:
-
From Setup, enter
static
in the Quick Find box, then select Static Resources. -
Click *New*l
-
In Name, enter
FX_Mobile_Rules
. -
In Cache Control, select "Public".
-
Click Choose File.
-
Select the FX_Mobile_Rules file and click Save.
When you upload a new FX_Mobile_Rules file, the validation rules in the new file replace any existing validation rules.
-
Test the validation rule:
-
Access FieldFX Mobile.
-
New validation rules don’t activate until after you sync. -
Add a record and enter invalid data.
A warning should display when you enter invalid data.
Test a validation rule thoroughly before activating it. A poorly designed validation rule can prevent users from saving or syncing data.
-
Validation Rule Builder
You must define validation rules for FieldFX Back Office and FieldFX Mobile separately.
The Validation Rule Builder makes it easier to add validation rules that work system-wide.
How It Works
When you run the Validation Rule Builder, it:
-
Analyzes FieldFX Back Office to look for validation rules.
-
Creates a new FX5__Mobile_Rules static resource containing every validation rule in FieldFX Back Office.
-
Creates a backup copy of the current FX5__Mobile_Rules file for your org.
-
Replaces the existing FX5__Mobile_Rules file with the new FX5__Mobile_Rules file.
-
Uploads the backup copy of the previous FX5__Mobile_Rules file to the static resource list for your org.
Once the Validation Rule Builder uploads a new FX5_Mobile_Rules file, the validation rules listed in the file work systemwide.
Setting Up the Validation Rule Builder
-
From Setup, enter
remote
in the Quick Find box, then select Remote Site Settings. -
Click New Remote Site.
-
In Remote Site Name, enter
SFDCToolingAPI
. -
In Remote Site URL, enter the domain in which your org runs.
To get the URL for your domain, copy the first part of the URL from the address bar in your browser:
Use your customized my domain URL that is specific to your org instead of your instance specific URL. You can find your my domain here.
Don’t use instanced URLs when logging in to Salesforce with code or as a user. When your org is moved to another Salesforce instance, code using the instanced URL breaks. If you find instanced URLs in your code, replace them with your My Domain login URL or the default Salesforce login URL. See Log In to Salesforce with Code for more information.
The Remote Site URL field is case-sensitive.Make sure the URL you enter uses the correct capitalization. -
Click Active and then click Save.
-
Complete one of the following:
Setting up to Automatically Run
-
From Setup, enter "apex" in the Quick Find box, then select Apex Classes.
-
Click Schedule Apex.
-
In Job Name, enter
Validation Rule Builder
. -
In Apex Class, select "ValidationRuleHandler".
-
Select how often you want the Validation Rule Builder to run.
Select a frequency of at least once per week. -
Click Save
Running the Validation Rule Builder Manually
Prerequisite
-
Select Utilities → Apex Execute.
-
Enter the following script:
System.debug(FX5.FXWorkerLauncher.DoWork('FX5.ValidationRuleHandler', null));
-
Click Execute.
The Validation Rule Builder:
-
Analyzes FieldFX Back Office to look for validation rules.
-
Creates a new FX5__Mobile_Rules static resource containing every validation rule in FieldFX Back Office.
-
Creates a backup copy of the current FX5__Mobile_Rules file for your org.
-
Replaces the existing FX5__Mobile_Rules file with the new FX5__Mobile_Rules file.
-
Uploads the backup copy of the previous FX5__Mobile_Rules file to the static resource list for your org.
-