Merge multiple PDF URLs into a single merged PDF URL
Overview
This article demonstrates how to use the SharinPix mergePdfUrls Apex method and the MergePdfUrlAutomation invocable action to combine multiple PDF URLs into a single merged PDF URL. You can use this feature in Salesforce Flows and custom Apex code.
Automatically Merging PDF URLs Using Salesforce Flow (Admin-Oriented)
The MergePdfUrlAutomation is an Apex Action designed to merge multiple PDF URLs into a single URL. In the following sections, we will demonstrate how to implement this action within a Salesforce Flow (Admin-Oriented). We will configure a Flow on the Case object to automatically merge PDF URLs from related SharinPix Form responses whenever a Case status is updated to 'Escalated'. View the flow configuration below for a step-by-step walkthrough.
Additionally, we will outline how to merge multiple PDF URLs utilizing the Apex Method mergePdfUrls (Developer-Oriented).
Input Parameters
PDF URLs
List<String>
The list of PDF URLs to be merged.
Filename
String
The desired filename for the merged PDF document. This parameter is optional and defaults to 'merged.pdf' if left blank.
Output Parameter
Merged PDF URL
String
The generated URL of the merged PDF document.
Using this in Apex (Developer-Oriented)
For custom code implementations, the SharinPix Utils class provides the method mergePdfUrls which can be used to merge multiple PDF URLs.
Method Signature:
mergePdfUrls(List<String> listPdfUrls, Map<String, Object> options)
Implementation Example
The following snippet illustrates how to instantiate the SharinPix utility class, prepare a list of URLs, define options, and execute the merge method.
Configuring the Flow to merge associated Form Response PDFs of a Case Record
Use Case: Merge all SharinPix Form Response PDF URLs linked to a Case Record into a single PDF when the field 'Status' is updated to Escalated using Salesforce Flow.
Step 1: Initialize Flow Builder
Navigate to Setup.
In the Quick Find Box, type Flows and select it.
Click New Flow and select Record-Triggered Flow.
Click Create.

Step 2: Configure the Record-Triggered Flow
Select the Case object.
Trigger the Flow when a record is updated.
Add an entry condition with condition requirements set to All Conditions Are Met (AND) and the field Status equals Escalated.
Set When to Run the Flow for Updated Records to Only when a record is updated to meet the condition requirements.
Optimize the flow for Actions and Related Records.
Add Asynchronous Path.

Step 3: Add a Get Records element to retrieve SharinPix Form Responses
Add a Get Records element in the Asynchronous Path.
Set the object to SharinPix Form Response.
Set the Condition Requirements to All Conditions Are Met (AND).
sharinpix__PdfUrl__c
Is Null
False
sharinpix__ParentRecordId__c
Equals
Triggering Case > Case Id
Set the Sort Order to Descending and Sort by to CreatedDate.
Select All Records to Store.

Step 4: Loop and Build List Of URLs
Create a new Resource of data type Text Collection.

Add a Loop element that will go through the Form Responses retrieved in Step 3.

Add an assignment element in the For Each path that will add the SharinPix Form Response PDF URL to the resource variable ListOfPdfUrls that we created in Step 4.

It should look like this:

Step 5: Add the Invocable Action
Add an Apex Action element in the Asynchronous Path after the loop we built in Step 4, and select the Merge PDF URLs (MergePdfUrlAutomation) action.

Assign the variable ListOfPdfUrls we created in Step 4 to the PDF URLs input parameter.
Specify a name in the Filename input parameter. Note: This is optional. If left blank, the default filename will be merged.pdf.

Step 6: Update the custom field Merged PDF URL
Add an Update Triggering Record element after the Apex Action in the Asynchronous Path.
Select the custom Merge PDF URL field that was added to the Case object.
For the value, select the Merged PDF URL output resource received from the Apex Action in Step 5.

The final flow should look like this:

Demo
When a Case record's Status is updated to Escalated, the Flow triggers automatically. It merges the associated Form Responses and saves the resulting merged URL into the designated custom field.

Clicking the merged URL initiates the download of the combined PDF. The image below demonstrates how the Form Responses were merged into a single PDF document.

Last updated
Was this helpful?

