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

Dynamic Content in Attachment?

Hello people,


We have a requirement where we have to send email  on submission of a form. The email should have an attachment which has dynamic content based on the record. I couldn't find any OOTB feature that will allow me to do so. But if I missed something here, please advice.


Coming to doing this using Apex, in my submit code (it's just a simple button click), I am inserting contacts and then using a visualforce page which is rendered as pdf to give me a blob which I'm then attaching to my email. The visualforce page has StandardController, so passing the id would give me record-specific data. 


However, the issue I am facing here is that when the .getContent() method is called from my code, I get an "unable to retrieve object" error. Is it that since the record has just been inserted and immediately I'm using it's standard controller?

It is the same issue here too :


Any ideas/solutions?  


Why not using a VF email template ?

You could have a PDF as attachment.


But I can have a single attachment for all emails, so it will not let me have dynamic data for each email




With a VF email template, you have dynamic data, like a registration form populated as a PDF attachment.

You can also have the same file as attachment.