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');
            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);
             newCase.FrCCC_Delivery__c.addError('The case already has the same delivery number');
  • If i understood correctly you want to display error first time if delivery number is already there and if user try to save next time you doesn't want to display error message right.
    – Pavan tej
    Commented Dec 18, 2017 at 14:38
  • Yes you are right..
    – Rizvana
    Commented Dec 18, 2017 at 14:45

1 Answer 1


if i am not wrong, the add error method stops the data from commiting to the Database. So there is no chance for your workflow rule to fire after the addError method.

  • In this case,Do we have any other option??
    – Rizvana
    Commented Dec 18, 2017 at 14:46
  • Not sure if you will be able to error message(warning kind of ) and still allow user to save record in database. Probably you can have some sort of status field. You can update that field with error message "delivery already exist". this way ur user also will be able to know the error but d record will be commited to DB. so 2nd time if they try to save you need not do any action since you already displayed error msg in a field. Commented Dec 18, 2017 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .