0

I can attach a file to a Lightning emailTemplate using one of the emailTemplate editors in Salesforce but I have not been able to find the attachment record that makes this relationship possible.

If, for example, I have an emailTemplate with id '00X0t000000MJ24EAG' and I attach a file to it, I can verify that the file is related to the emailTemplate by opening the emailtemplate in the emailtemplate editor associated with the email component on a lead record page. The file will be shown attached to the emailTemplate below the email HTML body rich text editor (image attached). However, when I query the DocumentAttachmentMap object with either of the following two queries, no results are returned (I also queried ContentDocumentLink):

select id from DocumentAttachmentMap where parentID = '00X0t000000MJ24EAG'

or

select id from DocumentAttachmentMap

How do I find the record which associates the file I attached with the Lightning emailTemplate?

enter image description here

0

Solved this. The documentAttachmentMap is kind of a red herring. Although the API reference states that it "maps the relationship between an EmailTemplate and its attachment, which is stored as a Document," I couldn't see how it was actually used in this example. The relationship between a Lightning EmailTemplate and attachments is determined by a ContentDocumentLink. I've appended the Apex code I used to attach a file to an emailTemplate, which is the same as the code used to attach a file to any other record.

ContentDocumentLink contentlink=new ContentDocumentLink();
contentlink.ShareType= 'V';
contentlink.ContentDocumentId = '0690t000000cmOgAAI';
contentlink.LinkedEntityId = '00X0t000000MJ24EAG';
insert contentlink; 

My question related to a project where I created a replacement for the Lightning emailTemplate system. Understanding the relationship between emailTemplates and files was necessary so that I could query for any emailTemplate attachments before sending a template-based email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.