+ Start a Discussion
Syed Abid ShahSyed Abid Shah 

How to enable auto response email to customer from apex trigger

I have a existing apex trigger class which avoid duplicates case creation by checking regular expression approach. however this apex trigger is sending communication email to case owner stating the case cannot by created for so and so regex in email subject line...however instead of triggering email to case owner we want the same email to be triiger to customer who originaly sent email with regex in email subject.
below is our current apex trigger:
trigger CheckSubjectRegex on Case (before insert) {

    for (Case c : Trigger.new) {

        if ( c.Subject.substring(0,3)== 'Re:' || c.Subject.substring(0,4)== 'Fwd:' || c.Subject.substring(0,3)== 'RE:'||c.Subject.substring(0,4)== 'ref:' || c.Subject.substring(0,4)== 'FWD:'||c.Subject.substring(0,3)== 'FW:') {

            c.addError('LQ may not be able to create a Case because it may be a Reply or Forward');



brahmaji tammanabrahmaji tammana
I think this is possible with SingleEmailMessage method. I am not sure how efficient it is ?

Senders email address is stored in field Web Email so we can use it in ToAddress why replying.
Can you confirm how are you sending the communicaton to case owner ?

Syed Abid ShahSyed Abid Shah
Hi Brahma,

Thanks for reply.
I am using below trigger: as soon it sees any regex in email subject it will shoot email to case object owner.
My Apex trigger

The response from trigger looks like below:
"From: support@salesforce.com (mailto:support@salesforce.com) [mailto:support@salesforce.com]
Sent: Monday, March 06, 2017 8:39 AM
To: Black, Kimberly
Subject: Sandbox: Email-to-Case: Error(s) encountered while processing
The following errors were encountered while processing an incoming email:
FIELD_CUSTOM_VALIDATION_EXCEPTION : LQ may not be able to create a Case because it may be a Reply or Forward