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
Manjunath T NManjunath T N 

How to pass the parameter from trigger to validation rules?

I have a trigger on Contract Object, whenever the Contract record is updated the contract section in the associated opportunities will also get updated with the latest Contract data but while updating Contract record, Contract section in associated Opportunities is not updating instead I am getting validation errors which is created on Opportunity object.
Now I want to stop Opportunity validation rules when I update the contract section of Opportunity object from Contract trigger. Is there anything that we can pass from trigger to validation rules to stop validation rules errors?  Please help me.
 
Ravi Dutt SharmaRavi Dutt Sharma
In the Opportunity trigger, you can keep an entry condition. 
if (a static boolean variable) {
       // your opportunity trigger goes here
}

In your contract trigger, set the value of this boolean variable to false (default value will be true). In this way, you will be able to skip the Opportunity trigger whenever an update happens on Contract object.
Manjunath T NManjunath T N
@Ravi Dutt, Thanks for your response but in my scenario I don't want to skip Opportunity trigger because whenever the Contract is updating I need to update the associated opportunities(Contract section) also but I want to skip validation rules on Opportunity.
Ravi Dutt SharmaRavi Dutt Sharma
Ok. got it. Then maybe you can use a custom setting here. In the custom setting, have a boolean field, say Skip Validation Rule, with a default value of false. Use this field in your validation rule to bypass the validation rule whenever it is required. At the very beginning of your Contract trigger, update this field to true, so that the validation rule is skipped. At the end of the trigger, mark the field again as false.

In the validation rule, keep a condition as below

IF(Skip_Validation_Rule__c, <Your exisitng validation rule comes here>, false)
Manjunath T NManjunath T N
@Ravi Dutt, I think your solution will work but again if that is the case then I need to edit all my available validation rules (50+) on Opportunity object which is again a big task.

Solution which I have implemented is:
I have converted the opportunity validation rules (2 validation rules) which are causing this issue to Apex code (Opportunity Trigger) and I have created one global boolean variable. So whenever I update opportunities from Contract? before opportunity update, I will set the value of boolean variable to true and then I will update the opportunity after updating opportunity, again I will set back the value of boolean variable to false. in Apex code (Opportunity Trigger) I have written a condition that if the boolean variable value is set to true then I will skip the validation rule which is converted into apex code so that I will not get these validation errors and opportunity will get update.