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
anil.ax822anil.ax822 

Person account contact sharing using apex trigger

Hi,

In person account type,i need to change the field access levels to 'edit' using apex trigger,but for person account record type the contact sharing setting will be controlled by parent, when i tried to write trigger code on account, to chane the contact field access levels,i am getting error like below 

 

Error: Compile Error: Field is not writeable: ContactShare.ContactAccessLevel at line 91 column 18  


the code is 

 

ContactShare cs = new ContactShare();

 cs.ContactAccessLevel = 'Edit'; 

 cs.ContactId = contact.Id;   

 Database.SaveResult accountInsertResults = Database.insert(cs, false);

 

Please help me 

Raghavendra Raju K SRaghavendra Raju K S
Hi Anil,
  
Am also faced similar issue while writing a trigger on Contact.
Error: Compile Error: Field is not writeable: ContactShare.ContactAccessLevel at line 91 column 18 

OWD for Contact is ''Contolled By Parent" by default, once the OWD of contact is changed to Private the error got fixed (My Developer Edition). Seems like in order to Share the records, the Object OWD should be Private.

Much Appreciated, If any one provides new solutions for this. 

Thanks
Raghu