I have 2 triggers on case and everything is running fine when using email2case. I created another trigger to populate a custom field in case. When the new trigger is activated the email 2 case doesn't create a case or any other functions that it usually does. Why would this code create this behavior?

    for (Case caseObj :Trigger.new) {
        if(caseObj.Origin == 'Email') {
            EmailMessage toEmail = [SELECT ToAddress FROM EmailMessage WHERE Incoming = true LIMIT 1];
            String te = String.valueOf(toEmail);
            System.debug('Email To Address is ' + toEmail);
            caseObj.Customer_Support_Email__c = te;

  • Are they three separate triggers or are you using a helper/utility class? – Girbot Feb 11 '15 at 22:31
  • @Girbot They're separate triggers. Do I need to bulkify them into one so I can control the order that they're fired? – kwiknick Feb 11 '15 at 22:35
  • 2
    If you're going to write a bunch of little triggers like this, I think you should put them into a class and use a trigger handler to do the rest – EricSSH Feb 11 '15 at 22:38
  • +1 with EricSSH. Plus remove that SOQL from within the for loop - you will hit governor limits with any mass insert or updates. – Girbot Feb 11 '15 at 22:45

I ended up bulking all the triggers into a Master Trigger and calling out to the three separate triggers which I turned into classes. I can't find the place I found a good example that I used, but I wanted to thank Girbot and EricSSH for pointing me in the right direction.

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.