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
ExeterExeter 

Cant create AccountTeamMember with AccountAccessLevel = "Edit" with API?

I've been round-and-round with this one.  All I'm trying to do is create an AccountTeamMember object and then use sforceService.create() to add it.   I can do it if I don't set AccountAccessLevel = "Edit".  If I don't, AccountAccessLevel is set by default to "Read". The problem is, I want AccountAccessLevel to be "Edit".  If I set AccountAccessLevel = "Edit", then when I execute the create() method the following exception is thrown:

 

Unable to create/update fields: AccountAccessLevel. Please check the security settings of this field and verify that it is read/write for your profile.

 

I've tried everything to remedy this situation, including setting the API user to the top role of the company (CEO), making the API user the owner of the account, checking every capability in the API user's profile, and creating account sharing rules.  Nothing makes a difference.  In fact, I can log in as the API user and create AccountTeamMembers with "Edit" access at Salesforce.com-- just not with the API. 

 

Has anyone been able to do this?  Please help.

Best Answer chosen by Admin (Salesforce Developers) 
ExeterExeter

Finally!  Creating the AccountShare object was the real key.  My errors after implementing that occurred because I was trying to set AccountShare.RowCause = "Team", which is not allowed from the API and not necessary, and I was not setting AccountShare.OpportunityAccessLevel, which is required.  My working code is below. 

 

Thanks for all the help!

 

AccountTeamMember newAccountTeamMember = new AccountTeamMember();

 

// Cannot set AccountAccessLevel here-- not allowed with the API.  Defaults to "Read"
newAccountTeamMember.AccountId = accountId;


newAccountTeamMember.TeamMemberRole = userAccountTeamMembers[i].TeamMemberRole;
newAccountTeamMember.UserId = userAccountTeamMembers[i].UserId;
newAccountTeamMembers[i] = newAccountTeamMember;

 

//Should not set AccountShare for the owner but for others
if (userAccountTeamMembers[i].UserId != account.OwnerId)
{
    AccountShare newAccountShare = new AccountShare();
    newAccountShare.AccountAccessLevel = "Edit";
    newAccountShare.AccountId = accountId;
    newAccountShare.OpportunityAccessLevel = "Read";
    newAccountShare.UserOrGroupId = userAccountTeamMembers[i].UserId;
    newAccountShares[i] = newAccountShare;
}

 

All Answers

SrikanthKuruvaSrikanthKuruva

so once you create the account team member by default the access level is set to read. now go to account share check for the account share record using account id and user id. set the accesslevel to read/write here. this should solve your problem.

let me know if this works

raseshtcsraseshtcs

I think what you will need to do is create an account team member and then immediatly add a row in the account share table with the correct set of permissions..

Hope it helps

ExeterExeter

Sadly, I'm implementing this solution and running into the same issue:

 

                In our new code, we are adding the AccountTeamMember with default AccountAccessLevel (Read), and then trying to create an AccountShare object for each new AccountTeamMember with RowCause = “Team”.  But as with before, we are getting an error.  The error is:

 

Unable to create/update fields: RowCause. Please check the security settings of this field and verify that it is read/write for your profile.

 

                …Same as before.  We’ve again tried to set the Role of the API user to “CEO” (top of the company) to make sure it’s not a permissions issue.  Here is our adjusted code…

 

AccountTeamMember newAccountTeamMember = new AccountTeamMember();

 

// Cannot set AccountAccessLevel here-- not allowed with the API.  Defaults to "Read"

newAccountTeamMember.AccountId = accountId;

newAccountTeamMember.TeamMemberRole = userAccountTeamMembers[i].TeamMemberRole;

newAccountTeamMember.UserId = userAccountTeamMembers[i].UserId;

newAccountTeamMembers[i] = newAccountTeamMember;

 

// Should not set AccountShare for the owner but for others

if (userAccountTeamMembers[i].UserId != account.OwnerId)

{

    AccountShare newAccountShare = new AccountShare();

    newAccountShare.AccountAccessLevel = "Edit";

    newAccountShare.AccountId = accountId;

    newAccountShare.RowCause = "Team";

    newAccountShare.UserOrGroupId = userAccountTeamMembers[i].UserId;

    newAccountShares[i] = newAccountShare;

}

 

Still trying!!!!!!!

ExeterExeter

Thanks for the hint in "Updating" the AccountShare record but that too didn't work.  When instead of creating the AccountShare records I tried to first query them for the account and then update them with AccountAccessLevel = "Edit", I got this error message:

 

Unable to create/update fields: UserOrGroupId. Please check the security settings of this field and verify that it is read/write for your profile.

 

Same issue.  So frustrating...

 

 

ExeterExeter

Actually, when I had the proper AccountId set for the AccountShare object, the exact exception is:

 

Unable to create/update fields: UserOrGroupId, AccountId. Please check the security settings of this field and verify that it is read/write for your profile.

ExeterExeter

...and when I add RowCause =  "Team" to the update record the exception cites all 3 fields:

 

Unable to create/update fields: UserOrGroupId, AccountId, RowCause. Please check the security settings of this field and verify that it is read/write for your profile.

 

Any further hints?

SrikanthKuruvaSrikanthKuruva

did you check if you are able to add the account team member and edit the access to read/write from UI?

ExeterExeter

Yes.  I can log in as the API user and do it from the UI with no problem.  Thanks.

ExeterExeter

Finally!  Creating the AccountShare object was the real key.  My errors after implementing that occurred because I was trying to set AccountShare.RowCause = "Team", which is not allowed from the API and not necessary, and I was not setting AccountShare.OpportunityAccessLevel, which is required.  My working code is below. 

 

Thanks for all the help!

 

AccountTeamMember newAccountTeamMember = new AccountTeamMember();

 

// Cannot set AccountAccessLevel here-- not allowed with the API.  Defaults to "Read"
newAccountTeamMember.AccountId = accountId;


newAccountTeamMember.TeamMemberRole = userAccountTeamMembers[i].TeamMemberRole;
newAccountTeamMember.UserId = userAccountTeamMembers[i].UserId;
newAccountTeamMembers[i] = newAccountTeamMember;

 

//Should not set AccountShare for the owner but for others
if (userAccountTeamMembers[i].UserId != account.OwnerId)
{
    AccountShare newAccountShare = new AccountShare();
    newAccountShare.AccountAccessLevel = "Edit";
    newAccountShare.AccountId = accountId;
    newAccountShare.OpportunityAccessLevel = "Read";
    newAccountShare.UserOrGroupId = userAccountTeamMembers[i].UserId;
    newAccountShares[i] = newAccountShare;
}

 

This was selected as the best answer
DevWannabeDevWannabe

Exeter,

 

Is it possible to see more of your code.  I am new to this and trying to determine where/how userAccountTeamMembers[i] is generate.

 

Thanks!

ArnoldFBArnoldFB
So here's a newb follow up question.   I'm an admin, not a developer in my org.  I'm interested in finding someone to write a trigger which will run on a daily basis, iterate through our list of accounts and create account team member records based on a list of territory rules defining who should be assigned to these accounts based on Billing state.  I'm hearing from somone on my team that you can't create account team members with Apex, yet here's this thread.  So I'm hoping for feedback on this.   Is it do-able?  Thanks,
Darth PlagueisDarth Plagueis
ArnoldFB - I am not sure how to do this but we should chat. It is possible. I'd be happy to talk through it with you.