Reputation: 467
I have been trying to write some custom workflows for our org but I am stuck on a particular issue. I know how to create attachments and link them to a new email, but I want to do the same with templates? I understand how to use the SendEmailFromTemplateRequest class, but I haven't found a way to link attachments to it. I found this article but I need more detail on how to use the InstantiateTemplateRequest. I've tried to tinker with it using this as a guide but so far I've not had luck.
My needs are that I need to create an email from a template and then attach files to it that are dynamically generated.
Upvotes: 4
Views: 3690
Reputation: 467
I found what I needed here, but I noticed that I still needed to Create the email object using the IOrganizationService helper. Basically I created the InstantiateTemplateRequest, thend passed it into the IOrganizationService Execute() function and then retrieved the Email object from the InstantiateTemplateResponse object. After I had the Email I then edited and passed it into the IOrganizationService Create() function. After that I sent it along using a SendEmailRequest object which also needs a IOrganizationService Execute() call.
Upvotes: 3
Reputation: 557
I am not very sure about how you are actually going to use the templates. But one work around could be that you can send the email in the same way you send with attachments. Create some logic to get the string content of the template, perform string handling operations as per requirement(Usually there are only a few fields in template that are to be modified and most of the text remains same). Now pass this string to the body of the email as string. I dont think there should be any trouble in this. Please correct me if I am missing some thing or misunderstood the complete question.
Upvotes: 1