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:
-
If the record passes validation, the record saves.
-
If the record doesn’t pass validation, a warning displays and you can’t save the record until you enter valid data or discard your changes.
Validation rules also run when you change the status of a record:
-
If the record passes validation, the record transitions to the new status.
-
If the record doesn’t pass validation, a warning displays and you can’t change the status until you enter valid data or discard your changes.
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:
-
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.
-
-
Click Save
-
-
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. Using the tool you can:
|
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
-
In Name, enter "FX_Mobile_Rules"
-
In Cache Control, select "Public"
-
Click Choose File
-
Select the FX_Mobile_Rules file
-
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
Basics
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 FX5Mobile_Rules file with the new FX5Mobile_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:
For example:
https://na43.salesforce.com
The Remote Site URL field is case-sensitive.Make sure the URL you enter uses the correct capitalization. -
Click Active
-
Click Save
-
Complete one of the following:
Scheduling the Validation Rule Builder to Run Automatically
Prerequisite
-
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.
-