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
adi salesforceadi salesforce 

trigger to share record on case

trigger casetotal on Case (after insert) {
        list<caseshare>share=new list<caseshare>();
    user u=[select id,name from user where name =:'karthik'];
    for(case c:trigger.new){
if(c.priority=='high'&&c.origin=='email'){
            caseshare cs=new caseshare();
                cs.caseid=c.id;
                cs.UserOrGroupId=u.id;
                cs.RowCause='manual';
                cs.CaseAccessLevel='all';
                share.add(cs);  
            }
}
insert share;
}  



could you correct this code because I am getting the following errors
field is not writable caseid;
field is not writable userorgroupid;
field is not writable caseaccesslevel;
field is not writable rowcause;
 
Jack Yu@TokyoJack Yu@Tokyo
Hi, Your code is good, no problem at all.
The reason is your Sharing Settings of Case is 【Public Read/Write/Transfer】.
so there is no caseshare object at all, it is not exist.


You need set 【Sharing Settings】as below.

【Security Controls】⇒【Sharing Settings】⇒【Edit】

set 【Default Internal Access of 】of case object as below.
【Private】or【Public Read Only】


If you do as what i told you,caseshare object will be created automatically,
of caurse you need to wait for some minutes.



User-added image


User-added image

Please mark as best answer if the above helps,thank you.