I wrote this logic inside a before insert/update trigger to apply a validation logic. But I am getting error saying - SObject row does not allow errors. Althought the text inside addError is appearing in the debug log but its not showing up in the call object as desired from the code. Below is the code. Kindly assist on how to avoid the error.

 trigger Call_Sample_Limit_Check on Call2_Sample__c (before insert, before update) {  
 if (Trigger.new != null) {
  Map<Call2_c,Integer> callErrorMap = new Map<Call2__c,Integer>();
  Set<Call2__c> callErrorSet= callErrorMap.keySet();
      for(Call2__c c:callErrorSet ){
                c.addError('You ve exceeded your limit for this call');
  • 4
    Your trigger is on Call2_Sample_vod__c but you are trying to add the error to a Call2_vod__c object. Is that a typo? You will also need to include the logic from Call_Sample_Limit.callSample if you want an answer to your problem. – BarCotter Jun 25 '15 at 11:30
  • I had an issue once with a trigger that did a validation and returned an error with 'addError' too. Turned out to be my fault, because Salesforce doesn't allow you to use this method in an object that is already in the database (or at least that was my conclusion). – Renato Oliveira Jun 25 '15 at 14:09

This error arises when you try to call addError in a trigger but call it on a record that is not in the trigger collection, which is exactly what you are doing. You can only validate records that are being acted on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.