+ Start a Discussion

transferring case from apex

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






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) 



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.