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?