You need to sign in to do that
Don't have an account?
PreussenBlau
Apex Trigger Stopped Cold - Validation Rule is the Culprit
We have an apex trigger that updates account records with some contact data. We also have a validation rule on the account record which prevents users from updating one field based on the absence of a value in another field. Some of our account records are already in violation of the validation rule since the user area didn't want us removing data to comply with the rule but instead wanted to force users to enter more data when the go to update an account via the gui.
The issue occurs when a user updates a contact. The apex trigger is activated on the contact update and tries to update the corresponding account record with data. But the update fails if the validation rule kicks in and the existing account data is in violation of the validation rule.
Is it possible to add a line of formula code to a validation rule to recognize a trigger (as one would recognize a user profile NOT($Profile.Name = "System Administrator"), or role) and thereby avoid activating the validation rule?
The issue occurs when a user updates a contact. The apex trigger is activated on the contact update and tries to update the corresponding account record with data. But the update fails if the validation rule kicks in and the existing account data is in violation of the validation rule.
Is it possible to add a line of formula code to a validation rule to recognize a trigger (as one would recognize a user profile NOT($Profile.Name = "System Administrator"), or role) and thereby avoid activating the validation rule?
The only result is an unneccesary email notification of the trigger update and the validation rule violation. It would be nice to be able to avoid this but it's not a big deal.
Most of the time our validation rules are for when a user edits a record but we want Apex to be able to update the record regardless of the validation rule. But if we wanted the rule to be enforced with apex we could do that too if there was an "isApex" function.
From a system standpoint I'm not sure if this is possible but it would take a thorn out of my side as any updates that are blocked with the rule and I have to update manually and that sort of defeats the purpose of apex.
Message Edited by TehNrd on 03-07-2008 01:43 PM
http://ideas.salesforce.com/article/show/10078198/ISAPEX_Function_for_Validation_Rules http://ideas.salesforce.com/article/show/10078198/ISAPEX_Function_for_Validation_Rules
Message Edited by TehNrd on 03-10-2008 01:00 PM
We have been able to handle this in the following way:
I find it easy to use date fields, but you could use a number field and increment it or a string and just generate a random string each time to put in there. The point is that you have a field that will change and only System Admins (or code running as System) can modify.