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
a459295360a459295360 

insert not allowed on AccountShare

HI,today, I use AccountShare object, but I get two problems, first one is: Field(AccountShare's all field)  is not writeable

 

 The second is:insert not allowed on AccountShare.

 

 I hope the very grateful to help me to solve the master,thanks!!!

 

//my apex

AccountShare thisAccountShare = new AccountShare();  
              thisAccountShare.userorgroupid=userId;  
              thisAccountShare.accountid = accId;  
              thisAccountShare.accountaccesslevel = 'Edit';   
              thisAccountShare.ContactAccessLevel = 'Edit';
              listAccShr.add(thisAccountShare);

 

insert listAcShr;

imuino2imuino2

Apparently what happens is that ContactAccessLevel isn't writable, you can check it on the Eclipse schema.

Go to AccountShare object -> fields -> ContactAccesLevel and then click on Access you will see that writable is not on the tree list.

Anyway i did remove the line that setted up that field but another error came up, you were missing to fill a required field called OpportunityAccessLevel. Finally i added that line and the code looks like this:

;
AccountShare thisAccountShare = new AccountShare();  
              thisAccountShare.userorgroupid=UserInfo.getUserId();  
              thisAccountShare.accountid = a[0].Id;  
              thisAccountShare.accountaccesslevel = 'Edit';
              thisAccountShare.OpportunityAccessLevel = 'Edit';
              listAccShr.add(thisAccountShare);
insert listAccShr;

 

This did work and inserted an AccountShare object.

 

Ignacio.

chetan_vaidya1.275893907413507chetan_vaidya1.275893907413507

Still the Same problem.

Field is not writeable: AccountShare.UserOrGroupId

sandeep1989sandeep1989
did you get a slution to this?
Bow BharathBow Bharath
Try go to account sharing setting and make it private.