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
indoberto lerma 10indoberto lerma 10 

Email to case not creating cases

Hi, according to some users in my org, when they are sending emails to the verified email addresses for Email to case, they are getting an error and cases are not being created in some scenarios.

the message they are getting is the following.

The following errors were encountered while processing an incoming email: 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY : CaseTrigger: execution of AfterInsert 

caused by: System.DmlException: Delete failed. First exception on row 0 with id a0Z0P00000JD2wYUAT; first error: ENTITY_IS_DELETED, entity is deleted: [] 

Class.CaseManagement.afterInsertUpdateDelete: line 318, column 1 
Class.CaseEventHandler.afterInsert: line 807, column 1 
Trigger.CaseTrigger: line 26, column 1 


it seems that the problem is with the case trigger but i am not sure why.

this is the trigger:

// 
// (c) 2015 Appirio, Inc.
//
// **Case Trigger
//
// 2.6.2015    Sandy       Original S-259411
// Code added(New method called from handler logic added) - Padmesh Soni (Appirio Offshore - 11/24/2105) - S-349948
// 

trigger CaseTrigger on Case (before insert, before update, before delete, after insert, after update, after delete, after undelete) {

//populate collections used in event handler
CaseEventHandler  handler = new CaseEventHandler(trigger.new, trigger.old, trigger.newMap, trigger.oldMap);

for(SkipTrigger__c skipTrg : SkipTrigger__c.getAll().values()){
  if(skipTrg.name == userinfo.getUserID().subString(0,15)){
    return;
  }
}

//call event handler methods
if(Trigger.IsInsert) {
  if(Trigger.isBefore) {
    handler.beforeInsert();
  } else {
    handler.shareTemporaryOwner(Trigger.newMap,Trigger.oldMap);//Added MS S-538921 [26th Jan 2018]
    handler.afterInsert();
  }
} else if (Trigger.IsUpdate) {
  if(Trigger.isBefore) {
    handler.checkUserForAssignedGroups();
    handler.beforeUpdate();
    handler.updateClosedStatus(Trigger.oldMap, Trigger.new); //Story# S-452906 Added to update Case status with + BB
   // handler.autoPopulateVisitDateAndTime(trigger.new); //Added by mandeep for case# 00189981 //Commentedfor case 00192372 this and added the following
    handler.autoPopulateVisitDateAndTime(trigger.new, Trigger.oldMap); //Added by Sneha on 00192372
  // handler.autoPopulateVisitDateAndTimeTest(trigger.new, Trigger.oldMap); //Added by Sneha on case 00195265

   

  } else {
    //handler.afterUpdate();
    //Modified By Vipul Jain for Story#S-474834 on May, 04, 2017
    handler.updateFeeds();
    handler.shareTemporaryOwner(Trigger.newMap,Trigger.oldMap);//Added MS S-538921 [26th Jan 2018]
    //END - Vipul Jain for Story#S-474834 on May, 04, 2017

  }
} else if(Trigger.isDelete) {
  if(Trigger.isBefore) {
    //NO BEFORE DELETE METHODS DEFINED AT THIS TIME
  } else {
    handler.afterDelete();
  }
} else if(Trigger.isUnDelete) {
  //NO UNDELETE METHODS DEFINED AT THIS TIME
  }

    /***** Code added - Padmesh Soni (Appirio Offshore - 11/24/2105) - S-349948 *****/
    //Code Changes start here
    //Check for event type
    if(Trigger.isAfter) {

        //Check for request type
        if(Trigger.isInsert) {

            //Call helper class method to populate fields mapping for FQRS Cases
            CaseEventHandler.populateFieldsOnFQRSCases(Trigger.new);
            CaseEventHandler.updateNumberOfDays(null, Trigger.New);//Added by Kritika Bhati for S-523626
        }
        //Start Added by Kritika Bhati for S-523626
         if(Trigger.isUpdate) {
            CaseEventHandler.updateNumberOfDays(Trigger.OldMap, Trigger.New);
    }
        if(Trigger.isDelete) {
            CaseEventHandler.updateNumberOfDays(Trigger.OldMap, null);
    }
        if(Trigger.isUndelete) {
            CaseEventHandler.updateNumberOfDays(null, Trigger.New);
    }
        //END S-523626
    //Code Changes stop here

Any ideas on what i need to do ?

 
Shawn Reichner 29Shawn Reichner 29
Looks like your trigger is calling Handlers which are associated Apex Classes.  Chase those down and post thier code here for more help, as we can not see what thos ehandlers are doing.   Looks like the error message is stating the record that is to be updated has been deleted, but from your description it seems as if you are trying to get new cases to be created, so that is strange.  Can you double check that your users are not including an old refID in the subject line or body of the email that is being sent, and if so this would then try to update a current case that exists, and that could be deleted and that would cause this error message.  Start there and if that is not the case, please look up thos ehandlers and post them here so we can help further.  
indoberto lerma 10indoberto lerma 10
the code is not complete since is too long, i paste the parts where its mentioned on the error (bold)

 * Apex Class: CaseManagement
    * Description: To update the Priority Field.
    * Created By: Sudhir Kr. Jagetiya
    * Created Date: 19 Feb 2013
    *
    * Modified By : Alka Taneja
    * Modified Date : 6 Jan, 2014
    * Case : 00058234
    * Description : Insert and delete the custom setting record to stop calling future method again and again
    */
public without sharing class CaseManagement {
    
    static Map<String, Respectful_Workplace_Priority__c> respectfulWorkspacePriorities = Respectful_Workplace_Priority__c.getAll();
    static final String CASE_RECORD_TYPE_RESPECTFUL_WORKSPACE = 'Respectful Workplace - Report';
    static final String CASE_RECORD_TYPE_LAWSUIT = 'RW Lawsuit';
    static final String CASE_RECORD_TYPE_EEOC = 'RW EEOC';
    static final String CASE_RECORD_TYPE_WORKERS_COMP = 'Workers\' Comp'; //S-295266 [Harendra 4/9/2015]
    static final String CASE_PRIORITY = 'A';
    static Map<String,Schema.RecordTypeInfo> rtMapByNameForCase = null;
    public static Boolean isData = true; // Added by Mohit for Story S-389908
    
    /* 
     * Description: Public method that will be invoked on before insert or update event of trigger.
     * @param: Trigger.new
     * @param: Trigger.oldMap
     * @return: void
     */
    public static void beforeInsertUpdate(List<Case> newList, Map<Id, Case> oldMap) {
      /* Start Jai Gupta S-198895 on Apr 03,2014*/
      if(oldMap == null || oldMap.size() == 0) {
          setEmpAcctId(newList, oldMap); //S-295266 [Harendra 4/9/2015]
          webToCasePopulateFields(newList, oldMap);



    // Added for the Case #00058234
        //START - Case# 00215814 - NP [18-12-2017]
        List<Stop_calling_future_method__c> scfm = new List<Stop_calling_future_method__c>([SELECT Name FROM Stop_calling_future_method__c]);
        if(scfm.size() == 0){
          CaseManagement.futurMethod(contactIDs, caseListIds, deletgeTrigger);
        } else {
          //Stop_calling_future_method__c scfm = Stop_calling_future_method__c.getAll().values()[0];
          delete scfm;
        }//END - Case# 00215814 - NP [18-12-2017]



//Update cases
            if(casesToUpdate.size() > 0) {
              
              // Insert custom setting record
              Stop_calling_future_method__c ob = new Stop_calling_future_method__c(Name=String.valueOf(System.now()));//Case# 00215814 - NP [18-12-2017]
              insert ob;
              
              // Update records
              update casesToUpdate;
            }
        }
Shawn Reichner 29Shawn Reichner 29
Thanks, can you advise which Object this ID belongs to in your error message?  Thsi is not a Case ID...a0Z0P00000JD2wYUAT
indoberto lerma 10indoberto lerma 10
Hi, i ca not find any record in the org with that id, all i could find is that the error message makes reference to a line 318 which is the one in bold where it says Delete sfcm; 
this makes reference to a custom settings named Stop calling future method and is a list but this list is empty not sure if this could be affecting or not.

 
Shawn Reichner 29Shawn Reichner 29
Yeah I would look for this Id in your custom setting, seems like it may have been hardcoded somewhere. Just a shot in th edark at this point.