Apex Aide apexaide

A Smart Salesforce Dynamic PDF Solution: Generate with Field Selection, Attach, & Email

By Salesforce FAQs· Salesforce FAQs· ·Intermediate ·Developer ·13 min read
Summary

This solution demonstrates how to build a dynamic PDF generation feature directly on a Salesforce record page using LWC, Apex, and Visualforce. It solves the common problem of manually creating and uploading PDFs by allowing users to select desired fields for the PDF, generating it automatically, attaching it to the record, and emailing it to customers with a single click. Salesforce pros can implement this approach to streamline document sharing workflows, minimize errors, and deliver tailored PDFs from within Salesforce seamlessly.

Takeaways
  • Use a Visualforce page as a PDF template dynamically displaying selected fields
  • Leverage Apex Queueable jobs to asynchronously generate and attach PDFs
  • Implement LWC UI for field selection and triggering Apex methods
  • Automate emailing attached PDFs to record's customer email address
  • Embed the LWC component on record pages for a seamless user experience

While working as a Salesforce Developer , I received a client requirement. The client wanted a way to send a  summary of a Salesforce record , such as Account details, invoice information, or other record data, to customers in PDF format. They wanted this process to happen directly from the record page without any manual work. Client Requirements: The client asked for the following features: Add a button on the record detail page labeled  “Generate PDF .” When the user clicks this button, a pop-up window should open. In the pop-up, the user should see a list of all fields available on that object. The user can select only the fields they want to include in the PDF using checkboxes. After clicking the Done button, a properly formatted PDF should be generated. The generated PDF should automatically get attached to the same record in the Files / Notes & Attachments section. They also requested one more feature: Another button labeled  “Send Email to Customer .

ApexSalesforce TutorialsCreate Dynamic PDF in Salesforce