1

I'm using Email Service and 3rd Party app to accept and create leads when email is sent to long Email Service address. What is the best way to send an autoresponse to the email address of the sender? Can I use Lead Autoresponse or is that exclusively for Web-to-Lead?

Using 3rd Party app "Email to Lead (OR) Email2Lead (OR) LeadFromEmail" by EZSAAS.

2
  • 1
    You're using InboundEmailHandler?
    – sfdcfox
    Commented May 26, 2017 at 13:07
  • As its a managed package (EZSAAS) I cannot see if it is using InboundEmailHandler but I can't imagine it is processing inbound emails any other way. See additional info above that I'm just about to add.
    – Bartley
    Commented May 26, 2017 at 13:12

1 Answer 1

4

If the package provides a method to specify the option to use the EmailHeader.triggerAutoResponseEmail flag, use it. Otherwise, one of the two following triggers should probably work:


trigger AfterLeadInsert on Lead (after insert) { 
    Lead[] newLeads = [SELECT Id FROM Lead WHERE Id = :Trigger.new];
    Database.DMLOptions autoResponseOptions = new Database.DMLOptions();
    autoResponseOptions.triggerAutoResponseEmail = true;
    Database.update(newLeads, autoResponseOptions);
}

trigger AfterLeadInsert on Lead (after insert) { 
    Lead[] newLeads = [SELECT Id FROM Lead WHERE Id = :Trigger.new];
    Database.DMLOptions autoResponseOptions = new Database.DMLOptions();
    autoResponseOptions.triggerAutoResponseEmail = true;
    for(Lead record: newLeads) {
        record.setOptions(autoResponseOptions);
    }
    Database.update(newLeads);
}

I provide both options here, because sometimes one or the other doesn't seem to behave as documented, so you'll need to test. You'll probably also want to limit this code to just certain lead sources or something specific, because as written, this will always send an email, even for manually created leads.

This code was adapted from this help article.

2
  • OK thx @SFDCFox, I've two questions: does the above trigger discriminate between leads created via web2lead and email2lead or does it always fire when a lead is created? and is the autoresponse only work as standard when an email is created via webtolead?
    – Bartley
    Commented May 26, 2017 at 13:25
  • 1
    @Bartley Autoresponse is automatically done for web2lead, but can be enabled in SOAP API and Apex Code using the EmailHeader. The code above triggers for all leads, web2lead, email2lead, manually created leads, leads created using the import wizard, etc. If you want to restrict it to certain scenarios, modify the code as you like.
    – sfdcfox
    Commented May 26, 2017 at 13:29

You must log in to answer this question.

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