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
tonantetonante 

Keep Opportunity Team Members using Apex when Changing Account Owner who is also an Account Team Sales Director

HI: I just wanted to solicit comments or ideas  concerning this issue:
We need to  programmatically keep the Opportunity Team Members and Send an email to the new account owner instead of doing it manually. So we'd use a trigger.

I know there is an idea out on the Success Community which is up for votes on how to handle this but has not reached the vote limit to pass yet:
https://success.salesforce.com/ideaView?id=08730000000cGUJAA2

However can't we just do these following procedural steps in Apex? Please let me know your ideas or comments because I really want to know if this makes any sense before I code it. Thanks much for your help:

If account owner is changing:
  1. Select each Opportunity Team Member (OTM) object using the Opportunity's Account Id
  2. Delete the old Account Team Member (ATM) Role of Sales Director
  3. Store the OTM object in a list of OTMs
  4. Insert the new Account Owner as the ATM's new Sales Director.
  5. Upsert the OTM list.
  6. Send email to the new Account Owner.
 I am assuming that once the Owner has been changed and has been Addeed as the new Sales Director in the Account Team, that these Oppotunity Team Member objects will not be kept when opportunities are transfered to the new owner if I don;t do those steps.