You need to sign in to do that
Don't have an account?

SObject row does not allow errors message
Hey guys, I have a simple trigger before change:
I get the error message SObject row does nto allow errors on line 19. I know that you can use the addError method for only those records that are avaliable in Trigger Context. But I thought i fixed it? How do I fix this?
trigger AssemblyDiaryEditValidation on Assembly_diary__c (before update) { Set<Id> aids = new Set<Id>(); Set<Id> saids = new Set<Id>(); Set<Id> sraids = new Set<Id>(); for(Assembly_diary__c a :trigger.old) { aids.add(a.Id); saids.add(a.Service_Appointment__c); } ServiceAppointment[] sa = [Select Id From ServiceAppointment where Id in :saids]; AssignedResource[] ar = [Select Id, ServiceResourceId From AssignedResource where ServiceAppointmentId in :saids]; if(ar != null) { sraids.add(ar[0].ServiceResourceId); } ServiceResource[] sr = [Select Id, RelatedRecordId From ServiceResource where Id in :sraids]; for (Assembly_diary__c b :trigger.old) { for(integer i = 0; i < Trigger.new.size(); i++) { if(sr != null) { if(sr[0].RelatedRecordId != UserInfo.getUserId()) { b.addError('Nejste oprávněni upravit tuto položku'); } } } } }
I get the error message SObject row does nto allow errors on line 19. I know that you can use the addError method for only those records that are avaliable in Trigger Context. But I thought i fixed it? How do I fix this?
on line 15 you are iterating through trigger.old, however addError only works on Trigger.New for updates.
Please refer to: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_exceptions.htm