Advanced Data: Executable Apex
Leverage Apex to Pull Custom Data Into Your S-Docs Templates
In this tutorial, you will learn how to reference Salesforce data into an S-Docs visual template using a custom Apex class. By completing this process, you will connect Apex-defined data, including records outside your primary object hierarchy, directly into your templates.
Prerequisites
Before starting this tutorial, ensure you have the following:
Salesforce Apex development experience
An active Apex class saved in your Salesforce org that utilizes the
SDOC.ApexExecutableinterface.Ensure the class includes a declaration configured for either an object or a list appended (e.g.:
SDOC.ApexExecutableObjectorSDOC.ApexExecutableList)
Step 1: Create an Apex Class
Create a custom Apex class in your Salesforce org that utilizes the
SDOC.ApexExecutableNavigate to Setup
Type Apex in the Quick Search
Select Apex Classes
Click New
Declare your Apex class structure to return either an object or a list. This declaration determines whether your data is applicable for Variables or Related Lists in the S-Docs template.
Define the data logic required to pull your target data, even if it resides outside the primary object hierarchy.
Click Save
The following is an example of a properly structured Apex Class for Visual Templates:
The Apex class example above is for demonstration purposes only and is not designed to fit any organizations unique use case.
Step 2: Accessing Apex Configuration in the Visual Template Editor
Navigate to the S-Docs Templates tab
Open the template you want to update or create a new template.
Launch the editor by clicking the Template Editor button.
Navigate to the Variables panel
and click the Advanced Data icon
.Select either the Objects or Lists tab, depending on how your Apex class was declared.
Locate the Apex subcategory.
Select the Click to Add option to launch the Edit Apex configuration panel.


Step 3: Configure and Map the Apex Class Data
On the right side of the panel, locate the Apex Class Selection drop-down menu and select the Apex class configured in Step 1.
Enter a descriptive name in the Label field.
Map the fields returned by your Apex class to the appropriate template fields using the drop-down menus in the Inputs section:
Select a Preview Record and click Validate to ensure the Apex class is collecting the expected results and they're mapped correctly.
Click Add Data Source.
Using Apex Collected Data in a Template

Since this example utilizes an Apex class defined for Objects, the resulting data variables will populate in the Variables panel under a new subcategory labeled with the same name as the label that was configured in the Edit Apex panel.
Click on a variable to add it to the template body.
Alternatively, the variables will display in the inline @ mention interface directly in the template body under the Data Source Relationships category.
Last updated
Was this helpful?


