+ Start a Discussion

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.accountid = accId;  
              thisAccountShare.accountaccesslevel = 'Edit';   
              thisAccountShare.ContactAccessLevel = 'Edit';


insert listAcShr;


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.accountid = a[0].Id;  
              thisAccountShare.accountaccesslevel = 'Edit';
              thisAccountShare.OpportunityAccessLevel = 'Edit';
insert listAccShr;


This did work and inserted an AccountShare object.




Still the Same problem.

Field is not writeable: AccountShare.UserOrGroupId

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