Create dynamic ways to interact with files within your Salesforce Organization. Key ways include:
-
Combine all attached fields into a Single PDF
-
Sort Attached Files Before Combining into a Single PDF
-
Filter Attached Files to Combine into a Single PDF
Combine All Attached Files into a Single PDF
The files associated with a record in Salesforce can be included in a combined PDF generated in Formstack Documents.
Step 1: In the Formstack Documents tab, click Data Routing in the Formstack Documents header and select New Data Route.
Step 2: Name the data route a name and click Create Data Route.
Step 3: Navigate to the Rules tab and add a new rule. (When creating a new data route, three empty rules will be added. One of these rules can be used and remove the rest.) Check Repeat this rule from the rule box. A new input field will appear in the rule.
Step 4: In the Send data to Document dropdown, select <
Step 5: In the Send data to Document field, type {$Url}.
NOTE: The merge field must match exactly (case-sensitive) in order for the Files to attach properly.
Step 6: In the Repeat this rule using the field (array) field use the merge field syntax and name the field anything. This will be the field we map in Salesforce Mappings later. In this example, {$Files} is used.
Step 7: Check Include in combined PDF.
At this step, the rule should appear like the below screenshot. The rule may have a different merge field name in the Repeat this rule using the field (array) field.
Step 8: Click Save, Next to save the rule.
Step 9: Go to the Formstack Mappings tab in Salesforce and click + New Mapping.
Step 10: A new mapping screen will appear. Give the mapping a Name and an optional Description.
Step 11: Select the Salesforce Object to use as the Primary Object. This has to be the object that has the files attached to it or a lookup field to the object that has the files attached to it.
Step 12: Select Route as the Formstack Resource and select the route previously created from the dropdown as the Data Route.
The new mapping should look like the following screenshot. The Salesforce Object and Data Route will vary.
Step 13: Click Save and Next.
Step 14: The fields available for mapping will load. This will include the URL field as well as the field created for the array of files. In this example, it is Files.
Do not map any Salesforce fields to the URL. Map the appropriate Files relationship into the array field. In the following screenshot, Child Relationship: Files (the files attached to the primary object, Contact) is mapped to Files.
Step 15: Lastly, click Save and Activate. The mapping is now ready for use.
Sort attached files before combining into a single PDF
When adding files associated with a record in Salesforce to a combined PDF, they can be sorted by any field, standard or custom, on the Content Version object.
To begin, set up the data route following the steps provided in the above section.
Next, in the rule in “Repeat this rule” using the field (array), add the appropriate modifier after the merge field name. Use the sort or multisort modifiers to adjust the order of the array of files:
Sort (one field)
To apply the sort modifier, add the pipe character ( | ) immediately following the merge field name, the word sort, a colon ( : ) and the API name of the field to use for sorting in single or double quotes ( ‘ or “ ).
Descending order
By default, the list will be sorted in ascending order, but to sort in descending order, add another colon ( : ) and the word desc in single or double quotes ( ‘ or “ ).
Multisort (multiple fields)
To apply the multisort modifier, use the word multisort rather than sort. Then, in a similar way, add each field, separated by a colon ( : ) using its API name in single or double quotes ( ‘ or “ ) followed by a colon ( : ) and the sort order (asc or desc).
NOTE: When attempting to use multisort and one of the fields being used for sorting is blank, the following error may be received:
Error: We're sorry, but an error has occurred: array_multisort(): Array sizes are inconsistent. Please try again.
When a field is blank in Salesforce, it will not always be returned in the API. This will cause the multisort formatting to fail.
Filter attached files to combine into a single PDF
Conditional logic can be used with the rules to filter out specific Files to merge into the combined PDF. This logic can include any merge field in the mapping or standard or custom field on the Content Version object in Salesforce.
Step 1: Set up the data route following the steps of the first use case.
Step 2: In the rule in Send data to Document, add an if condition merge tag around the URL merge tag ( {$Url} ). If {$Url} already exists in the field, select <
Step 3: In the condition of the if tag, reference the merge field using the Formstack Documents syntax of dollar sign ( $ ) and then the name of the merge field. If referencing a field on the Content Version object, use the exact API name. It is case-sensitive.
Considerations for managing files in Salesforce
- Files can be mapped and accessed directly from Salesforce Mappings for:
- the Primary Object
- any Related Lookup Objects
- Files attached to Child Objects cannot be accessed and mapped directly from Salesforce Mappings
- When mapping Files, any fields on the Content Version object are accessible within Formstack Documents, including custom fields.