0

I have trigger on Opportunity based on OwnerId. I am updating some picklist fields. When a User changes Account.OwnerId, the Opportunity triggers are not working.

As per docs, I understood Opportunity triggers or not working when Account owner changes.

Salesforce documentation

So, I create a process when Account Owner has been changed I do a field update on child Opportunity records. It works fine.

But, I have issue like in old opportunities sometimes didn't met certain validation rules either new mandatory fields or blank.At that time it is unable to change opportunity owner as well as account owner.But, it can't able to throw error it shows Workflow failed to update trigger some error is there any possibility to bypass validation rule's or i have to all update old records to work smoothly

2
  • 1
    When you are referencing the docs, please include a link and exact quote so we can follow along. – Adrian Larson Oct 13 '16 at 13:44
  • Also, please reserve blockquote (>) formatting for when you are actually quoting something. There are a few exceptions, but it will make your posts much less confusing. – Adrian Larson Oct 13 '16 at 14:13
2

If your data quality is poor, then yes you have to fix it for the flow to work. There are workarounds you can implement, but ultimately, any workaround will make your data quality worse, not better, and simply exacerbate the problem.

The least invasive modification to your flow/validations would be to add a checkbox on Opportunity, and set the checkbox to true for each record whose owner you wish to change. Then you have to modify each Validation Rule that is giving you trouble to ignore records with this flag set. And finally, you should add a Workflow Rule or additional flow that un-checks this checkbox every time it gets checked, so that future validations still work.

This rigamarole is probably more work (and will cause more technical debt) than just fixing the data.


If you cannot get your data to a clean state, you should instead use an Apex Trigger on Account to at least handle the errors gracefully. Graceful error handling is still a huge advantage of Apex Trigger implementations over Process Builder. It would be something like:

trigger Account on Account (after update)
{
    // obviously still follow One Trigger Per Object
    // and implement a Trigger Handler pattern

    List<Account> ownerChanged = new List<Account>();
    for (Account record : trigger.new)
        if (record.OwnerId != oldMap.get(record.Id).OwnerId)
            ownerChanged.add(record);

    List<Opportunity> children = [/*query*/];
    // set new field values
    try
    {
        update children;
    }
    catch (DmlException dmx)
    {
        for (Integer i = 0; i < dmx.getNumDml(); i++)
        {
            Opportunity child = children[dmx.getDmlIndex(i)];
            trigger.newMap.get(child.AccountId).addError(dmx);
        }
    }
}
4
  • Correct me if I'm wrong but whatever automated process that un-checks the checkbox would also cause the validation to fail right? – dBeltowski Oct 13 '16 at 14:04
  • Hmm, good point. You'd have to do some more rejiggering of the Validation Rules to make it work. Another point against that change. – Adrian Larson Oct 13 '16 at 14:05
  • 1
    I suppose you could do OR(Is_Checked, PRIORVALUE(Is_Checked)) to bypass the validation rule, but I agree that fixing the data is the better solution. – dBeltowski Oct 13 '16 at 14:07
  • After do field update.On the same process we can add another action to uncheck the checkbox. – Pavan tej Oct 13 '16 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.