+ Start a Discussion
btran3btran3 

Override validation rule with trigger

Hello,

 

I have a validation rule right now that requires you to select a task type besides the default when creating a new task.  I recently ran into a problem when our marketing automation tool tries to make a task in salesforce.  On the marketing automation forum for creating a task it does not have the option of selecting a task type so it is set to default which does not comply with my validation rule.  I wanted to know if I could write a trigger that would be able to set the task type before insert when you change the priority to something else besides the default so it will comply with the validation rule.  Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Noam.dganiNoam.dgani

Hi

 

you can use youre BEFORE TRIGGER solution since user defined validation rules run after before trigger:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

All Answers

sfdcfoxsfdcfox

Validation rules currently execute before the "before" triggers (at least, they appear to do so), so that option is right out. But, you could instead write a trigger to perform the validation, which could include more complex logic. Or, you could modify your validation rule to ignore users of a certain profile or username (which would presumably be the profile or username of your incoming integration requests).

Jerun JoseJerun Jose
To answer to your title question . No . you cannot override validation rules. You could however modify your validation rule to bypass certain records. I believe that the marketing tool records will have some identifier to distinguish them from other task records. You can use that identifier and the ISNEW() operator to bypass the new task records created.
Noam.dganiNoam.dgani

Hi

 

you can use youre BEFORE TRIGGER solution since user defined validation rules run after before trigger:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm

This was selected as the best answer
btran3btran3

Could you help me adjust the validation rule below to exclude any task that has the priority set to "PQRS"?  Thanks!

 

AND( ISNEW() , ISPICKVAL( Type , "None") )