If I use the below code then it throws an error:
Review all error messages below to correct your data. Apex trigger abc caused an unexpected exception, contact your administrator: abc : execution of AfterInsert caused by: System.FinalException: Record is read-only: Class.xyz: line 93, column 1
if((trigger.isInsert || trigger.isUpdate) && trigger.isBefore)
{
B2C_ServiceRoleService.encryptData(trigger.new);
}
if(trigger.isinsert || trigger.isbefore){
B2C_ServiceRoleService.copyAccountFields(trigger.new);
}
If I use below code then it works fine.
if((trigger.isInsert || trigger.isUpdate) && trigger.isBefore)
{
B2C_ServiceRoleService.encryptData(trigger.new);
B2C_ServiceRoleService.copyAccountFields(trigger.new);
}
- Value of
trigger.isinsert
=true
in both scenarios - Value of
trigger.isupdate
=false
in both scenarios - Value of
trigger.isbefore
=true
in both scenarios
I am not able to figure out why it throws an error in the first case. I encounter the error when I create new records.