function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DeekDeek 

Need Help on Trigger to restrict contact owner update from account

The requirement is to stop updating contact owner when the account owner is changed based on below 2 criterias

1.if the account_rating__c='High Rater'


jiah.choudharyjiah.choudhary

@dpat,

 

I would suggest you to replace the map value with the trigger's old value. i.e. :

 

mapAccountId_OwnerId.put(a.Id, a.OwnerId); ------------------> mapAccountId_OwnerId.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId);

 

This would replace Contact's Owner with Account's old Owner, Since it is standard functionality to update child's owner with parent's owner, This way you can update contact with old owner and hence indirectly avoid updating with parent's new owner.

DeekDeek

Hi Jiah,

Thx for the reply. But this is not working as expected.

Whenever I am changing from user A to user B its updating the the contact owner as user A which should not be the case.

 

The requirement is to update contact owner to user B always (standard functionality).

 

But the contact owner should not change:

 

1.if account_rating__c='High Rater' OR

2. new account owner (user B) = Chief Marketing Officer (account ownerid=005d0000001Jm8k)

 

Hope i am clear now.

Pls advise.

jiah.choudharyjiah.choudhary

@dpat,

 

Since it is the standard functionality, only thing you can do is reverse it based on your condition.