How to Create and Send PDF Via Email Using Salesforce Flow : Bijay Kumar
by: Bijay Kumar
blow post content copied from SalesForce FAQs
click here to view original post
**Summary of Creating and Sending PDFs via Email Using Salesforce Flow** In this tutorial, we’ll learn how to automate the process of sending a PDF to customers when they register for an event using Salesforce CRM. The process involves creating a public site where customers can fill out an event registration form, generating a PDF with their registration details, and sending it via email. ### Key Steps: 1. **Creating a Public Site and Form**: - Use Salesforce Flow to create a screen flow that allows customers to fill out an event registration form. - The information entered will be stored in the `Event Registration__c` object in Salesforce. - This form will be accessible to external users without needing Salesforce access. 2. **Generating PDF with Apex and VisualForce**: - An Apex class (`EventPassPDFController`) retrieves the registration data and passes it to a VisualForce page to generate a PDF. - The VisualForce page uses the `renderAs="pdf"` attribute to create a downloadable PDF file containing the registration details. 3. **Sending the PDF via Email**: - Another Apex class (`EventPassEmailSender`) generates the email content and attaches the PDF. - This class is invoked when a new record is created in the `Event Registration__c` object, ensuring the PDF is sent automatically. 4. **Triggering the Email**: - A record trigger flow is created in Salesforce to call the `EventPassEmailSender` class whenever a new registration record is created, ensuring the PDF is sent promptly. ### Conclusion: By following these steps, you can efficiently automate the process of sending personalized event registration confirmations as PDFs via email in Salesforce. This not only enhances customer experience but also streamlines event management. ### Additional Information: - Ensure you have the necessary permissions and access to create public sites and flows in Salesforce. - Familiarize yourself with Apex and VisualForce to customize the PDF content further. ### Relevant Hashtags for SEO: #Salesforce #SalesforceFlow #PDFGeneration #Apex #VisualForce #EventRegistration #CRM #Automation #EmailMarketing #SalesforceTutorials #SalesforceDevelopment
I was working as a System Administrator in a company that uses Salesforce CRM to manage event registrations.
The company wanted to automatically send a PDF to customers when they register for an event through a public site.
A record gets created in the Event Registration__c object after each registration. I need to add the registration details to the PDF and send it via email to the customer.
In this tutorial, we will learn how to create and send a PDF via email using Salesforce Flow. In that, I will explain the public site, how to create a PDF using a VisualForce Page and Apex, and how we can view it using Salesforce Flow.
Create and Send PDF Via Email Using Salesforce Flow
First, we will understand the event generation form and the public site where customers fill out the form for event registration.
1. Create a Form Using Screen Flow and Deploy it on a Public Site
First, let’s understand why we need to create the screen flow and add/deploy it on the public site.
We will create the screen flow to generate the event generation form, allowing customers to fill it out. The details provided by the customers will be recorded in the Event Registration__c custom object.

After creating the form, we need to share it with the external user. To give them access, we must add the form to the public site, allowing customers to fill out the form even if they don’t have Salesforce access.
I have written an article on how to create a screen flow and add it to the public site in Salesforce. You can check out: Create a Public Site and Add a Flow Component in Salesforce.
Below, I have provided a screenshot that shows the fields I added to the screen flow, which I then added to the public site.

When the customer fills in the details and saves the form, the record will be created in the Event Registration__c object.

As you navigate to the object, you can see the record has been successfully created. However, for these records, the Created By (user) will be Event Registration Site Site Guest User, which is the guest user assigned to the records created from the public site.
If you are experiencing issues viewing the form on the public site or creating a record, please refer to: Insufficient Access for Creating a Record.

In this way, we can create a public site and add a screen flow component to it, so that whenever anyone opens the site, they can enter the details, and the record will be created in the Salesforce object.
2. Generate PDF Using Apex and VisualForce Page in Salesforce
Now, let’s understand when the record gets created in the Event Registration object, and how we can create a PDF using those field values.
For that, we will use Apex and a VisualForce Page to retrieve data from the object and create the PDF in Salesforce.
Apex Class: EventPassPDFController – Retrieve Data From Object
In the Apex class below, we used getter and setter for interacting with the VF file that we will create in the next step.
After that, we retrieve the ID parameter from the current Visualforce page URL and store it in a variable regId of type ID.
Then, using that record ID, we fetched the record details using a SOQL query to pass those details to the VF page, where we will create a PDF for the record.
Next, we used exception handling to handle any errors that may occur while retrieving data from the Event Registration object.
public without sharing class EventPassPDFController {
public Event_Registrations__c registration { get; set; }
public EventPassPDFController() {
Id regId = ApexPages.currentPage().getParameters().get('id');
if (regId != null) {
try {
List<Event_Registrations__c> regList = [
SELECT Name__c, Event_Name__c, Registration_Date__c, Session__c, Email__c, Status__c FROM Event_Registrations__c WHERE Id = :regId LIMIT 1 ];
if (!regList.isEmpty()) {
registration = regList[0];
} else {
registration = new Event_Registrations__c(Name__c = 'Record Not Found');
}
} catch (Exception e) {
System.debug('Exception while querying Event_Registrations__c: ' + e.getMessage() + ' - ' + e.getStackTraceString());
registration = new Event_Registrations__c(Name__c = 'Query Error');
}
} else {
registration = new Event_Registrations__c(Name__c = 'No Id Provided');
System.debug('No Id parameter provided in URL.');
}
}
}
So this Apex controller class will retrieve the record details from the Salesforce object and pass those details to the VisualForce page.
VisualForce Page: EventPassPDF – Generate PDF
Now, we will create the VisualForce Page to generate the PDF for the record retrieved from the Apex controller class.
You can see that we are referencing the Apex controller class, where we retrieved the record details. To generate the PDF, we added the renderAs=”pdf” tag.
Next, to display the Label and its values, we used the <p> tag, and to retrieve the field values, we referred to the Apex class variable and the field API Name.
<apex:page controller="EventPassPDFController" renderAs="pdf">
<h1>Event Pass</h1>
<p><strong>Name:</strong> {!registration.Name__c}</p>
<p><strong>Event:</strong> {!registration.Event_Name__c}</p>
<p><strong>Date:</strong> {!registration.Registration_Date__c}</p>
<p><strong>Session:</strong> {!registration.Session__c}</p>
<p><strong>Email:</strong> {!registration.Email__c}</p>
<p><strong>Status:</strong> {!registration.Status__c}</p>
<p>Thank you for registering for the event. Please bring this Event Pass with you.</p>
</apex:page>
In this way, we can generate the PDF using Apex and VisualForce PDF in Salesforce.
Create Email Content and Add Generated PDF to Email Using Apex
Now, we will create the Apex class that will generate the email content and attach the PDF created on the EventPassPDF VF page.
But the Apex class does not execute automatically, so we need to call this Apex class from the record trigger flow when a new record is created.
Then pass the List<Id> regIds variable to the flow so that whenever a new record gets created, the flow will pass the record ID to this variable, and the Apex will know which record needs to generate a PDF and send it to the email address.
public class EventPassEmailSender {
@InvocableMethod
public static void generateAndSendInvocable(List<Id> regIds) {
generateAndSend(regIds);
}
public static void generateAndSend(List<Id> regIds) {
List<Messaging.SingleEmailMessage> emails =
new List<Messaging.SingleEmailMessage>();
for (Id regId : regIds) {
try {
Event_Registrations__c reg = [
SELECT Name__c, Event_Name__c, Registration_Date__c, Session__c, Status__c, Email__c FROM Event_Registrations__c WHERE Id = :regId LIMIT 1];
PageReference pdfPage = Page.EventPassPDF;
pdfPage.getParameters().put('id', regId);
Blob pdfBlob = pdfPage.getContentAsPDF();
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('EventRegistration.pdf');
attachment.setBody(pdfBlob);
attachment.setContentType('application/pdf');
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] { reg.Email__c });
mail.setSubject('Your Event Registration Confirmation');
mail.setPlainTextBody('Hello ' + reg.Name__c + ',\n\nAttached is your event registration confirmation.');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment });
emails.add(mail);
} catch (Exception e) {
System.debug('Error processing Event Registration Id: ' + regId + ' - ' + e.getMessage());
}
}
if (!emails.isEmpty()) {
Messaging.sendEmail(emails);
System.debug('Emails sent successfully from EventPassEmailSender.');
} else {
System.debug('No emails sent; no valid registrations found.');
}
}
}
In this way, we can generate the email content and attach the PDF to the email in Salesforce Apex.
3. Call the Apex Class to Send a PDF Email Using Salesforce Flow
Now, let’s create the record trigger flow that calls the EventPassEmailSender Apex class to send an email with an attached PDF whenever a new record is created in the Event Registration object.
For that, navigate to the Flow builder and create the Record Trigger Flow in Salesforce.
At the start, provide the following details:
- Object: Event Registration.
- Configure Trigger: A record is created.
- Optimize Flow: Actions and Related Record.
Then add the scheduled path so that after the record is created, the VF page can get some time to generate the PDF.

Now, add the Action element and search for the Apex class that we created for creating and sending the email.
After adding the class, provide the Label and API Name to the element. In the Set Input Values section, you will see the regIds, which are Apex class variables. For this variable, we need to pass the record ID of the newly created record.
After that, save the flow, debug it, and then activate it.

4. Proof of Concept:
Now I will show you the email that was generated after an external user created a record from the public site.
Below you can see the received email with attached PDF and other content that we added in the Apex class.

As you open the PDF, you will see the record details have been included in it.

In this way, we can utilize Apex, VisualForce Pages, and Flows to generate and send a PDF from Email in Salesforce.
Conclusion
I hope you have got an idea about how to create and send a PDF via email using Salesforce Flow. In that, I have explained the public site, including how to create a PDF using a VisualForce Page and Apex, and how to view it using Salesforce Flow.
You may like to read:
- Send An Email with Dynamic Attachments in Salesforce Flow
- Freeze User Accounts Using Salesforce Flow
- Send Email Alerts For Overdue Tasks Using Salesforce Flows
The post How to Create and Send PDF Via Email Using Salesforce Flow appeared first on SalesForce FAQs.
July 28, 2025 at 03:12PM
Click here for more details...
=============================
The original post is available in SalesForce FAQs by Bijay Kumar
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Post a Comment