You need to sign in to do that
Don't have an account?
Mark Lewis 21
Generating Autoresponse from Template when Lead is Created
Hello guys
I have code that automatically generates leads from my email. Now what I need is something that can inform the sender that their query is being processed. Now I have created a tigger to send the response but it doesnt seem to work. Is there something I am missing?
I have code that automatically generates leads from my email. Now what I need is something that can inform the sender that their query is being processed. Now I have created a tigger to send the response but it doesnt seem to work. Is there something I am missing?
trigger EmailToLeadResponseTrigger on Lead (after insert) { final String template = 'SalesLeadCreatedWebInquiries'; Id templateId; try { templateId = [SELECT id FROM EmailTemplate WHERE Name = :template].id; } catch (QueryException e) { //...handle exception if no template is retrieved, or create condition to set email body in code } List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>(); //Send a single mail to contact each created lead for (Lead l : [SELECT Name, Lead.Email FROM Lead WHERE Id in :Trigger.new]) { Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.setTemplateId(templateId); message.setTargetObjectId(l.Id); message.setWhatId(l.Id); message.setToAddresses(new String[] {l.Email}); messages.add(message); } }
try with below code it will help !
If your email field is mandate in Lead then you can remove the condition to check null inside for loop .
Let me know if it helps .
Thanks
Manoj
All Answers
The entire code is ok, however you didn't write email send logic. Please try this. I've added the last line and it will works.
Please mark it as a best answer if it really help
You can use out of box standard SFDC functionality for this i.e workflow rule. This will help you to send email alert messages to customer without writing any code and test classes.
Plz refer link for more info: https://help.salesforce.com/HTViewHelpDoc?id=creating_workflow_rules.htm
try with below code it will help !
If your email field is mandate in Lead then you can remove the condition to check null inside for loop .
Let me know if it helps .
Thanks
Manoj
Thank you so much for the responses. Now I have the autoresponse going with this code However, in my inbox it actually shows the user im using's email adress. Can I make this hidden or one of those "noreply@....com" emails where It just rejects replies to that given email?