In the Case Object I have a custom text field Delivery#
. If the delivery number value is duplicate the error message should be thrown and the users should allow to save the page. By that I mean in the first click of save option the error should be shown and the second click of save it should save.
I have written a trigger to show the error message if it is duplicate and created one checkbox field Isduplicate if still the users want to continue to save this checkbox should be selected but I don't want this field to be visible to the users, i have written the workflow rule and trigger to achieve this but somehow my workflow rule is not working.
Workflow rule : Rule Criteria
Case: Delivery #NOT EQUAL TO NULL.
Field to Update Case: Is record near to duplicate True
Trigger :
trigger duplicatechecktrigger on Case(before insert, before update) {
map<string, Case> caseMap = new map<string, Case>();
for(Case csold: system.trigger.new){
if((csold.FrCCC_Delivery__c!= null) && (system.Trigger.isInsert || (csold.FrCCC_Delivery__c == system.trigger.oldMap.get(csold.id).FrCCC_Delivery__c))){
if(caseMap.ContainsKey(csold.FrCCC_Delivery__c) && (!csold.Is_record_near_to_duplicate__c)){
csold.FrCCC_Delivery__c.addError('Another new lead has the' + ' same email address');
}else{
caseMap.put(csold.FrCCC_Delivery__c, csold);
}
}
}
for(Case csold: [SELECT FrCCC_Delivery__c FROM Case WHERE FrCCC_Delivery__c IN : caseMap.keySet()]){
Case newCase= caseMap.get(csold.FrCCC_Delivery__c);
if(!caseMap.get(csold.FrCCC_Delivery__c).Is_record_near_to_duplicate__c){
newCase.FrCCC_Delivery__c.addError('The case already has the same delivery number');
}
}
}