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
The_PhoenixThe_Phoenix 

Web-to-Lead auto-response email & attachments

We would like to set a web-to-lead form from which a person would be specifying product sheets request via a multi picklist field. Once the lead is entered in salesforce, an automated email with appropriate attachments (from the documents) would then be fired back at that person.  Is it possible to programatically attached documents to a template?
cmxintcmxint

Hi, The_Phoenix.

Answer to your question is "Yes, it is possible". But I can recommend only programmatical method of doing that, and it's kind of tricky... The main idea is that you cannot access email templates directly via API, but the trick is you can access attachments... So what I did to attach different files to my email template is:

1. Manually (via UI) attach single file of 0 length to email template. I named it 'main_attach.txt';

2. In my SendEmailNotification() method I run a query 

"SELECT Id, Body, ParentId, Name FROM Attachment WHERE Name='main_attach.txt'"

 (the name of primary attachment is hardcoded, but you can give an option to user to specify it). This query returns Attachment object which attached to email template. Its ParentId field contains ID of emailtemplate.

3. Temporarily delete this attach and create another attache(s) with bodies containing file(s) you need to attach. While creating those attaches it's necessary to specify ParentId field to assign them to your template - it should be a value of ParentId field you got in step 2.

4. Trigger workflow rule somehow (for your point it can be done by creating lead I suppose) which will compound email with all attaches you've created in step 3.

5. Set up email template to initial state - remove all attaches you've created in step 3 and assign 'main_attach.txt' attachment to template.

That's it. I do not claim it's perfect method, but it works at least - all my attempts to perform dynamical attacments creating were not successful.

HTH.

Message Edited by cmxint on 01-12-2005 05:07 AM