You need to sign in to do that
Don't have an account?
William Woodson 3
before update trigger read only error
I cannot figure out why this code is throwing the following error...
System.FinalException: Record is read-only
This code is in a helper method that receives a single object from the Trigger.New value and will alway be a single object not bulk. Error line appears to be this bit of code "hr.Date_Interviewed__c = date.today();" The trigger fired is a before update...
if (Trigger.isBefore && Trigger.isUpdate) {
Hiring_Audit__c hr = (Hiring_Audit__c) so;
if(hr.Stage__c == 'Submittal') {
hr.Date_Submitted__c = date.today();
}
else if(hr.Stage__c == 'Interview') {
hr.Date_Interviewed__c = date.today();
}
else if(hr.Stage__c == 'Offered') {
hr.Date_Offered__c = date.today();
}
else {
hr.Date_Applied__c = date.today();
}
update hr;
}
System.FinalException: Record is read-only
This code is in a helper method that receives a single object from the Trigger.New value and will alway be a single object not bulk. Error line appears to be this bit of code "hr.Date_Interviewed__c = date.today();" The trigger fired is a before update...
if (Trigger.isBefore && Trigger.isUpdate) {
Hiring_Audit__c hr = (Hiring_Audit__c) so;
if(hr.Stage__c == 'Submittal') {
hr.Date_Submitted__c = date.today();
}
else if(hr.Stage__c == 'Interview') {
hr.Date_Interviewed__c = date.today();
}
else if(hr.Stage__c == 'Offered') {
hr.Date_Offered__c = date.today();
}
else {
hr.Date_Applied__c = date.today();
}
update hr;
}
how you are setting the Hiring_Audit__c record in ==> Hiring_Audit__c hr = (Hiring_Audit__c) so ==> from Trigger.New() or Trigger.Old();
If you are using the Trigger.Old() to set the value in hr then change it as Trigger.New() because the Trigger.Old() also read only in before update.
All Answers
how you are setting the Hiring_Audit__c record in ==> Hiring_Audit__c hr = (Hiring_Audit__c) so ==> from Trigger.New() or Trigger.Old();
If you are using the Trigger.Old() to set the value in hr then change it as Trigger.New() because the Trigger.Old() also read only in before update.
Thank you so much, that was driving me crazy!