function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rich SpitzRich Spitz 

Custom validation vs. Trigger

I am not a developer,so bear with me. Can someone tell me whether you can customize a validation rule using VF or Apex or whether you need to write a Trigger to do the comparison. I am trying to compare a summary from 2 different tables, then pop up a message saying " Your Actual is greater than budget"

Thanks
Rich Spitz
Cory CowgillCory Cowgill
Rich, so a few clarifications that should help you understand my final answer.

In Salesforce.com there is a feature called "Validation Rules".

https://help.salesforce.com/HTViewHelpDoc?id=fields_useful_field_validation_formulas.htm

These are data level validations that you can easily implement without any Apex Code (Triggers, Classes) or VF Pages. It allows Business Analysts and non-developers to write rules to stop bad data from entering the system.

Validation rules execute at the database layer (They are not tied to a screen or user interface, they fire regardless of if the record is updated in the screen by a user, or a system integration via an API call.

Validation rules can only fire against 1 record at a time (the record being updated). You cannot do cross-object (AKA Cross Table) validations (unless they have a formula field / lookup relationship to each other, and only from Parent to Child).

Therefore, your requirement above cannot be done with a validation rule. To compare data across objects and prevent users from modifying the data you would want to use an Apex Trigger and Apex Trigger Handler to prevent this data from being entered in the system.

Hope that helps.