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
Bill NicholsonBill Nicholson 

Can someone help me to write a trigger that updates the account team member (adds) when a owner is edited and the record type is household.

Sukanya BanekarSukanya Banekar
Following is the code to set account team member if owner of the account has changed
trigger Accountteam on Account (after update, after Insert) {
        Id recordType= Schema.SObjectType.Account.getRecordTypeInfosByName().get('Household').getRecordTypeId();
        List<AccountTeamMember> lstTeam = new list<AccountTeamMember>();
        for(Account objAcc: trigger.newMap.values()){
            if(objAcc.OwnerId <> trigger.oldMap.get(objAcc.Id).OwnerId
              && objAcc.RecordTypeId == recordType ){
                AccountTeamMember objAccTeam = new AccountTeamMember();
                objAccTeam.AccountId =;
                objAccTeam.UserId = objAcc.OwnerId;
                objAccTeam.TeamMemberRole= 'Account Manager'; // you can change the role
        if(lstTeam<> null && !lstTeam.isEmpty())
            insert lstTeam;

Also replace TeamMemberRole with the value you want.

Hope this helps you.

Sukanya Banekar