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
ycaballeroycaballero 

Deleting the auto response email (CASES) after it has been sent

I have very basic knowledge of APEX and created the following code below.  The auto response is cluttering up my emails.  I would like for it to go out but then deleted.  The code below deletes it but it doesn't let the response go out. 

trigger Auto_generated_case_emails on EmailMessage (after insert) {
    List<EmailMessage> emDelList = new List<EmailMessage> ();
    for (EmailMessage em : Trigger.new)   // bulkified
       if (em.subject.contains('ACAMS Support'))
          emDelList.add(em);

    delete emDelList;


KevinPKevinP
Well, you've got some syntax issues in your code. Namely the lack of {} 's but if you add those, you should be off to a good start. Try something like this:
trigger Auto_generated_case_emails on EmailMessage (after insert) {
    List<EmailMessage> emDelList = new List<EmailMessage> ();
    for (EmailMessage em : Trigger.new) {   // bulkified
       if (em.subject.contains('ACAMS Support')) {
          emDelList.add(em);
       } 
    }
    
delete emDelList;

ycaballeroycaballero
Thank you for your response.  I modified the code and it did delete the email message from the case but it doesn't let the auto response go out.  It should send the auto response and then delete it from the case.