I need to write custom change owner functionality. I have a checkbox Keep Account Team - Transfers all account team members on the account to the new owner. How to create this functionality? There is no field for owner on Account team.


  • 2
    The field is called OwnerId.
    – Adrian Larson
    Jun 8, 2015 at 21:13
  • @AdrianLarson but how to use it? There is no such field in schema for AccountTeamMember and when I write select like this [Select OwnerId From AccountTeamMember] I receive an error "Compilation error: No such column 'OwnerId' on entity 'AccountTeamMember'." Jun 9, 2015 at 5:54
  • Your question is very unclear. Please elaborate on what you are trying to accomplish and what you have already tried.
    – Adrian Larson
    Jun 9, 2015 at 6:01
  • I need to create Change Account Owner functionality - repeat standard options + add new ones. There is a standard option Keep Account Team - "Transfers all account team members on the account to the new owner". And I can't understand how to transfer all account team members on the account to the new owner in Apex because I don't know how to set owner for AccountTeamMember. Is it clear now? Jun 9, 2015 at 6:50

1 Answer 1


Try using something like this:

Select ownerId, Id, (select id, accountId, account.ownerId from AccountTeamMembers ) from account

From this you can get all TeamMembers of an account, then change the owner of the accounts. You can not directly change the owner of all teamMembers, because TeamMember doesn't have an owner.

  • But is there a difference if I will do a simple query Select ownerId, Id, from account and change account owner OR if I will do your query? If AccountTeamMeber doesn't have an owner field, does it means that checkbox Keep Account Team simply do nothing with teams if its true, and removes teams if its false? Jun 9, 2015 at 11:55
  • You will need to query the accounts in the team members.. If u do a simple query [Select ownerId, Id, from account], then u are getting ownerId of account, but not the ownerId of accounts in team members. I dont understand the functionality of your checkbox. In your question, you want to change the ownerId of the accounts in the teamMembers. So, you can use my query(provided above) or this query also : select id, accountId, account.ownerId from AccountTeamMembers where AccountId =: '//id of Account ' . Then, update the Account.OwnerId of the records you got by using this query. Jun 10, 2015 at 14:37

You must log in to answer this question.

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