I have an issue in bypassing the validation rules, looked into all possible solution provided in the stackExchange for last one week, nothing is working for me. Please help me here.
Background: - Child Object "Opportunity-service" has lookup relationship with Opportunity object. - When inserting/updating "Opportunity-Service" record, a field "All-services" in Opportunity object is updated . - Opportunity object has standard field "Close date" it has validation rule. - Opportunity-service object has visualforce page and extention. - Opportunity-service object has a trigger called 'OpportunityserviceTrigger' - Opportunity object has a trigger 'OpportunityTrigger'. - OpportunityServiceTrigger updates the Opportunity object - It has update DML operation.
Issue: - When I insert or update Opportunity-service, it updates opportunity object('All-service' field) in opportunityServiceTrigger, performs validation rule on CloseDate in Opportunity object and operation fails.
** 2 Solutions I tried:**
- Created a customsettings field checkbox -'BypassCloseddateValRule' , default value is false(Unchecked). In opportunity-service trigger, I make checkbox BypassCloseddateValRule to true and update the opportunity. At end of the trigger, I make BypassCloseddateValRule to false. It is not working. Looks like it performs validation rules twice. First one goes throug fine. Second time, it fails
Solution2: - Created a checkbox on Opportunity object - 'BypassCloseddateValRule'. Default value is false. I make this checkbox 'true' and update the opportunity in OpportunityServiceTrigger. Created workflow rule on opportunity object to update this field as 'false'. It is also not working.
Can someone, please help me here.
Below is the validation rule on closedate on opportunity object.
ISPICKVAL(StageName, "1 - Qualification"),
ISPICKVAL(StageName, "2 - Proposal Under Development"),
ISPICKVAL(StageName, "3 - Proposal Delivered"),
ISPICKVAL (StageName, "4 - Sales Presentation")),
CloseDate < TODAY(),
$Setup. Expected_Commitment_Date_Check__c = FALSE,
When new opportunity created/edited, it should check for following validation rule
For stages 1 to 4, opportunity close date must be greater than today. I have added a custom-setting field Expected_Commitment_Date_Check__c to bypass the validation if opportunity updated from OpportunityServiceTrigger.
We want users to have this validation rule error message while they are working on opportunity page when they make update/insert.
When users create/update any related object like opportunity-service, it should ignore this validation rule. Otherwise user will be overwhelmed by seeing opportunity validation rule error on Opportunity-service VF page.