[SalesForce] Keep Account Team when Updating Account Owner even if “Keep Account Team” is not selected

I am brand new to triggers and am trying to accomplish a few things here since you cannot default the "Keep Account Team" checkbox on.

  1. Whether the "Keep Account Team" checkbox is selected or not, I need to keep the current Account Team when the Account Owner Changes.
  2. The Account Owner will always have a Team Member Role of "Account Manager." So if the Account Team already has a Account Manager on it, it needs to be deleted, and updated with the new Account Owner added to the Account Team.

Best Answer

We had a situation similar to this where users were not selecting the right boxes and selecting the wrong ones.

The solution I ended up doing was to remove the Account Owner field from the page layout and replaced with with a custom account owner field:

HYPERLINK('/' & OwnerId, Owner.FullName__c) & ' ' &
HYPERLINK('/apex/AccountOwnerChange?Id=' & Id, '[Change]')

(Note: we opted not to care about the profile image, there are some tricks that can be done to facilitate this if you care).

Then I made a VF page that used the standard controller with a custom extension.

This allowed me to remove the unwanted checkboxes and customize the behavior completely. We did think about taking the approach that you are trying to take with using a trigger to correct the mistakes but we opted against this for usability; very confusing to a person when the click a box or don't click a box and see the opposite of what they thought would happen. We also wanted effectively non of the built in functionality to work and this was a much easier way to achieve that as opposed to writing a bunch of logic to undo each and every one of the checkboxes. There is also the risk that when the changes are being made manually (not necessarily by changing the owner) that your trigger jumps in inappropriately.

Related Topic