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
Jan Kopejtko 2Jan Kopejtko 2 

SObject row does not allow errors message

Hey guys, I have a simple trigger before change:
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) {
    ServiceAppointment[] sa = [Select Id From ServiceAppointment where Id in :saids];
    AssignedResource[] ar = [Select Id, ServiceResourceId From AssignedResource where ServiceAppointmentId in :saids];
    if(ar != null) {
    ServiceResource[] sr = [Select Id, RelatedRecordId From ServiceResource where Id in :sraids]; 
    for (Assembly_diary__c b :trigger.old) {
    for(integer i = 0; i <; 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?
Jay Wang 2Jay Wang 2
Hey Jan,

on line 15 you are iterating through trigger.old, however addError only works on Trigger.New for updates.

Please refer to: