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
vishesh91vishesh91 

transferring case from apex

hi all , in my apex code following line is causing error

 

  

trigger.new[i].OwnerId=selectedUserId;

 

 

here selectedUserId is a variable holding userId to which case should be transferred.

 

Error :  execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.CaseRoutingTrigger

 

 

The system admin profile has transfer cases permission enabled.

 

Any guidance will be of great help

Best Answer chosen by Admin (Salesforce Developers) 
sanjdevsanjdev

Hi,

 

You've tried to update records that set off the trigger in an after trigger. Records in trigger.new are read only in an after trigger.

 

if you intend to update records, best to use a before trigger.

 

or if it must be done in an after trigger, then you will have to re-query your recordset and update explicitly.

 

If it helps you then marked it as resolved. Do let know if any concerns.

 

Cheers

Sanj