[SalesForce] bypass validation rule upon merging

How can we bypass validation rule when using the oob merge process. I can't figure out what field identifier to use as my criteria on validation rule that will tell me that user is processing merge and validation rule should be bypass. please advise

Best Answer

Take the advantage of order of execution of triggers ,validation rules and workflows.

1)Your custom validations run after before triggers

2)Your workflow rules run after your triggers .

3)Triggers and Merge Statement document https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_merge_statements.htm

Using the above conclusion ,create a boolean field on the record named "ByPassValidation" and avoid this from pagelayout .

As per document when merge happens ,after delete trigger on looser record gives a MasterRecordId ,Query records with Ids equivalent to MasterRecordId and update the boolean ByPassValidation=true

Now In validation rules use this flag and AND your current validation with this field .Make sure by default your ByPassValidation is unchecked .

Draft a workflow rule now to again uncheck the ByPassValidation flag .In the entire process there can be chance for trigger to fire once more due to wrokflow making an update ,Use Static boolean to avoid this condition .