You need to sign in to do that
Don't have an account?
OnurK
SObject row does not allow errors
Can you helpm for adding the error message here? I am getting SObject row does not allow errors message
trigger beforeCase on Case (before insert, before update) {/* // List <Case> cs = Trigger.new; // TaxNumberDuplicate.checkDuplicates (cs); Set<String> taxNumber =new Set<String>(); for (Case c : trigger.new) { taxNumber.add(c.Tax_Number__c); } List<Case> duplicatecaseList = new List<Case>(); for(Case c : [SELECT id, Tax_Number__c, permit_duplicate__c FROM Case WHERE Tax_Number__c IN: TaxNumber]) duplicatecaseList.add(c); for(Case cs : duplicatecaseList){ if(trigger.isInsert){ if(duplicatecaseList.size()> 0 && cs.permit_duplicate__c == FALSE && cs.Tax_Number__c != Null){ cs.Tax_Number__c.addError('ERROR!!!!!'); } } else if(trigger.isUpdate){ if(duplicatecaseList.size()> 0 && cs.permit_duplicate__c == FALSE && cs.Tax_Number__c != Null && System.trigger.oldMap.get(cs.id).Tax_Number__c != System.trigger.newMap.get(cs.id).Tax_Number__c ){ cs.Tax_Number__c.addError('ERROR!!!!!'); } } } */ }
Hi OnurK
You are trying to add the Error on the record in duplicate list, which will not be possible. In your code duplicateList contains the list of existing records which have the similar tax number. Try the code below. I have optimized the code by including the permit_duplicate__c check in the query. And the Tax_Number__c null check before having it included in the list "taxNumber".
Hope this helps! :)
All Answers
y cant you try like this in all the places
cs.Tax_Number__c.addError('ERROR!!!!!'); replace this as trigger.new.tax_number__c.adderror('error'); and try
Hi,
First of all thank you for replying so quickly. After I replaced the code, I received another error
"Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Case>"
Thanks
Hi OnurK
You are trying to add the Error on the record in duplicate list, which will not be possible. In your code duplicateList contains the list of existing records which have the similar tax number. Try the code below. I have optimized the code by including the permit_duplicate__c check in the query. And the Tax_Number__c null check before having it included in the list "taxNumber".
Hope this helps! :)
Thanks shruthi,
It was great help.