I had posted the similar question earlier:

AccountTeam Member is not getting Read/Write access on Account?

Below is same code:

private void UpdateAccountTeam(Map<Id, SObject> newItems, Map<Id, SObject> oldItems) {

    List<AccountTeamMember> listOfAccountTeam = new List<AccountTeamMember>();
    List<AccountTeamMember> listOfDeleteAccTM = new List<AccountTeamMember>();

        List<AccountTeamMember> lisOfAccountTM = new List<AccountTeamMember>([Select TeamMemberRole, Id, userId, AccountId from AccountTeamMember where AccountId in:newItems.keySet()]);
        Map<String, AccountTeamMember> mapOfAccountTM = new Map<String, AccountTeamMember>();

        for(AccountTeamMember accTM:lisOfAccountTM) {
            String strKey = accTM.TeamMemberRole + accTM.AccountId;
            mapOfAccountTM.put(strKey, accTM);

        for(SObject newObj :newItems.values()) {
            Account newAccountObj = (Account)newObj;
            Account oldAccountObj = Null;

            if(oldItems!=Null) {
                oldAccountObj = (Account)oldItems.get(newAccountObj.Id);

            AccountTeamMember accTeamMember = Null;

            if(newAccountObj.SF_Director__c!=null && (oldAccountObj==Null || oldAccountObj.SF_Director__c!=newAccountObj.SF_Director__c)) {
                accTeamMember = getAccountTeamMember(newAccountObj);
                accTeamMember.TeamMemberRole = 'Salesforce Director';
                accTeamMember.userId = newAccountObj.SF_Director__c;

                String strMapKey = accTeamMember.TeamMemberRole + newAccountObj.Id;
                if(mapOfAccountTM.get(strMapKey)!=null) {
                    listOfDeleteAccTM.add(new AccountTeamMember(Id=mapOfAccountTM.get(strMapKey).id));


            if(Trigger.IsInsert) {
                accTeamMember = getAccountTeamMember(newAccountObj);

                accTeamMember.TeamMemberRole = 'Account Manager';
                accTeamMember.userId = newAccountObj.CreatedById;

        delete listOfDeleteAccTM;

        insert listOfAccountTeam;


private AccountTeamMember getAccountTeamMember(Account newAccountObj) {
    AccountTeamMember accTeamMember = new AccountTeamMember();

    accTeamMember.AccountId = newAccountObj.Id;
    accTeamMember.AccountAccessLevel = 'Edit';
    accTeamMember.OpportunityAccessLevel = 'None';
    accTeamMember.ContactAccessLevel = 'None';

    return accTeamMember;

OWD in my Org:

Account: Public Read Only

Contact : Private

Opportunity : Private

Case: Private

In my previous post, Issue was we had updated Contact from Private to Public Read Only and while creating account member, we were setting Contact access as Private. We had again changed Contact from Read Only to Private and modified the code.Above code is the same code and it creates Account Team Member when Account gets created but problem is it sets Account access as Read Only.

If you can check above code, I am setting access as Edit so it should set AccountAccess as Read/Write.

I have put the debug log before inserting AccountTeamMember and confirm that in the code it sets Account access as Edit but as soon as Account Team member gets inserted, it sets to Read Only not Read Write.

Is there any bug in recent release for accesslevel?

Has anyone faced this issue earlier?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.