0

We have a functionality in which we need to update ownership on Case when certain condition satisfies. So we went ahead and wrote 'Validation Rule' on Case.

For eg (I have not included more condition, but assume there are):

ISCHANGED(OwnerId) then throw Owner cannot be changed

This works well when someone changes the owner on Case. But if someone changes the account owner of account and mark these two checked.

Transfer account owner's open cases
Transfer all of this account owner's cases

This allows changing of owner on Case fields.

I tried writing the triggers.

For eg:

if (Trigger.isBefore && Trigger.isUpdate) {
    List<Case> lstCaseTriggerNew = Trigger.new;
    Map<Id, Case> mapCaseTriggerOldMap = Trigger.oldMap;
    for (Case eachCase : lstCaseTriggerNew){
        if(eachCase.OwnerId != mapCaseTriggerOldMap.get(eachCase.Id).OwnerId){
            eachCase.addError('Owner Cannot be changed via Apex');
        }
    }
}

But even triggers gets escaped when changing ownership of case via Account Change owner. Is there any way to still stop ownership on cases?

1

1 Answer 1

1

There are a few cases where special functionality doesn't fire triggers as you might expect. It appears that this is one of these cases. The Salesforce.com team has been rooting these out over the years and making more and more of these events fire triggers. I don't know where this case is on the list, but I suspect you're not the first to identify it. I would check ideas.salesforce.com and vote for this idea, or post it if the idea isn't already up there.

Check the Considerations for Changing a Record’s Owner using the link

Also, there are few scenarios where validation rules will not work when transferring the record owner. Refer the help article Link

2
  • I read those link already but none of those docs talks about case triggers not being fired. Commented Mar 5, 2022 at 1:28
  • I ran into this recently on change owner of Contact. If the current owner is owner of events belonging to the contact, the owner of the events changes but the Apex triggers on Event do not fire. On the other hand, if you convert a Lead to a Contact and change the owner in the process, Event owners may change and triggers ARE fired.
    – Ken
    Commented Oct 19, 2023 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .