+ Start a Discussion
Jayaramu T 9Jayaramu T 9 

while compiling the class i am getting folowing errors.

I am getting following errors in below code

Field is not writeable: AccountShare.AccountAccessLevel
 Field is not writeable: AccountShare.CaseAccessLevel
 Field is not writeable: AccountShare.OpportunityAccessLevel
 Field is not writeable: AccountShare.AccountId
 Field is not writeable: AccountShare.UserOrGroupId



if(z==0 && resgroup.get(asset.Reseller__c)!=null){
                    Accountshare ashare = new AccountShare();
                    ashare.AccountAccessLevel='Edit';
                    ashare.CaseAccessLevel='None';
                    ashare.OpportunityAccessLevel='None';
                    ashare.AccountId=asset.AccountId;
                    ashare.userOrGroupId=resgroup.get(asset.Reseller__c);
                    newshares.add(ashare);
                }
SandhyaSandhya (Salesforce Developers) 
Hi,

Refer below thread for similar discussion.

https://salesforce.stackexchange.com/questions/192936/how-to-fix-field-is-not-writeable-error
 
Best Regards,
Sandhya
Naren9Naren9
Try by changing your code like below:
                    List<Accountshare> newashares = new AccountShare();
if(z==0 && resgroup.get(asset.Reseller__c)!=null){

                    ashare.AccountAccessLevel='Edit';
                    ashare.CaseAccessLevel='None';
                    ashare.OpportunityAccessLevel='None';
                    ashare.AccountId=asset.AccountId;
                    ashare.userOrGroupId=resgroup.get(asset.Reseller__c);
                    newshares.add(ashare);
                }
update newshares;

Thanks,
Narendar




 
Guru Vemuru 11Guru Vemuru 11
Hi Jayaramu,
Please check your field level access for those fields. If it is read only in profile level you cannot update or edit fields through class.

Thanks
Guru Vemuru