You need to sign in to do that
Don't have an account?
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;
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.
Still the Same problem.
Field is not writeable: AccountShare.UserOrGroupId