### Updating Page Layouts in Salesforce Setup Source: https://kb.sdocs.com/knowledge-base/sdocs/installation/download-sdocs-upgrades This example demonstrates how to add a new field ('Allow Edit') to an S-Doc template record page layout within Salesforce Setup. It covers navigating the Object Manager, Page Layouts tab, and dragging fields to the desired location. This process ensures new fields from S-Docs updates are visible and usable. ```Salesforce Setup 1. Navigate to Setup. 2. Go to Object Manager. 3. Find and click on the S-Doc object. 4. Navigate to the Page Layouts tab. 5. Click 'Edit' for the relevant page layout. 6. Under the 'Fields' tab, find the 'Allow Edit' field. 7. Drag the 'Allow Edit' field to the desired area in the page layout. 8. Click 'Save'. ``` -------------------------------- ### Generate Documents in Batch and Combine Documents (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/generating-documents/s-docs-software-development-kit-documentsdk This example demonstrates generating documents for multiple records using multiple templates and then combining them into a single PDF using the CombinedDocumentHandler. The method returns a string representing the generated document. Note: The original text shows the return type as String, but the method signature and other examples imply an ID. This example follows the provided code structure. ```apex String generatedDocumentAsString = SDOC.DocumentSDK.generateDocsInBatch( new List { accounts[0].Id, accounts[1].Id }, new Set { accountReport.Id }, 5, new List { new SDOC.CombinedDocumentHandler() } ); ``` -------------------------------- ### Content Version JSON Field Assignment Example Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/overview-the-s-docs-template-editor This JSON example demonstrates how to preset Content Version file attributes when the 'Show Content Version JSON field' option is enabled. It maps field API names to values, including static text, merge fields, and literal values for various data types. ```json { "Checkbox__c": "true", "Date_Created__c": "{{!Opportunity.CloseDate}}", "Type_Picklist__c": "Three", "Type_Text__c": "{{!Opportunity.Name}}", "Decimal_Value__c": "12.34", "Integer_Value__c": "1234" } ``` -------------------------------- ### Basic Substitute Syntax Example Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/advanced-template-features Demonstrates the fundamental syntax for the 'substitute' attribute, showing how to define key-value pairs for data replacement. This basic structure can be expanded with multiple pairs and a catch-all value. ```xml Field__c ``` -------------------------------- ### Apex Example: Product Data Formatting Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic-sdocs/call-apex-classes-in-your-s-docs-templates This Apex code snippet demonstrates how to format product data, including description and code, within an S-Docs template. It constructs an XML-like string for product information. ```Apex return '' +             + 'Green fruit' +             + '3012' +             + '';     }     } ``` -------------------------------- ### S-Docs lineitemsSOQL Configuration Example Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/generate-a-component-template-for-each-record-in-a-related-list This snippet shows the structure for the `lineitemsSOQL` tag used in S-Docs Method 2. It includes the SOQL query, component definition, and column specifications. Ensure `columnFields="true"` and a `mergeFieldPrefix` are set on the component. ```html ``` -------------------------------- ### Install S-Docs License Key (v4.380 and below) Source: https://kb.sdocs.com/knowledge-base/sdocs/installation/install-and-renew-your-sdocs-license-key This snippet demonstrates how to install an S-Docs license key for versions 4.380 and below by creating a new template in Salesforce. The license key is pasted into the 'Document Version' field of the template. ```Salesforce Apex Template Name : License Key Description : [_Leave this blank_] Document Category : None Related To Type : Opportunity Template Format : PDF Document Version : [_Paste License Key Here_] Available For Use : [_Unchecked_] Initially Visible : [_Unchecked_] Allow Edit : [_Unchecked_] ``` -------------------------------- ### S-Docs Button URL for Standard Objects Source: https://kb.sdocs.com/knowledge-base/sdocs/installation/sdocs-quick-install-configuration-guide-salesforce-lightning This code snippet generates the URL for the S-Docs button, used to initiate document creation for a specific Salesforce record. It dynamically includes the record ID and object name. Ensure 'Opportunity' is replaced with your target object's API name. ```html {!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity'])} ``` -------------------------------- ### S-Docs Button URL with Lightning Navigation Source: https://kb.sdocs.com/knowledge-base/sdocs/installation/sdocs-quick-install-configuration-guide-salesforce-lightning This URL configures the S-Docs button to explicitly use Lightning navigation, which can resolve display issues in Salesforce Lightning. It includes the record ID, object name, and the lightningnav='true' parameter. Replace 'Opportunity' with your object's API name. ```html {!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity', lightningnav='true'])} ``` -------------------------------- ### Merging Cells for Product Name and Description Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/customizing-your-related-list-layout This example demonstrates combining the 'PriceBookEntry.product2.Name' and 'PriceBookEntry.product2.Description' into a single table cell using custom prefix and postfix attributes. This technique allows for more compact table layouts by grouping related data. ```html
``` -------------------------------- ### Export S-Docs Templates with SOQL Filter (Multiple Names) Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/moving-templates-from-sandbox-to-production This example shows how to use the SOQL OR operator to export S-Docs templates that match one of several specified names. This is useful for exporting a specific set of templates. ```plaintext WHERE Name='Quote' OR Name='Business Proposal' ``` -------------------------------- ### S-Docs Callable Apex Class Example (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic/call-apex-classes-in-your-s-docs-templates This Apex class demonstrates the structure required for S-Docs Callable Apex. It must be global and return a map of strings to strings. The 'call' method handles different actions, and the example 'getMergeFieldMapExample1' function retrieves an Opportunity record and constructs a map of merge fields. ```Apex global class CallableApexTest implements Callable { public Object call(String action, Map args) { switch on action { when 'getMergeFieldMapExample1' { return this.getMergeFieldMapExample1((String)args.get('recordId')); } when else { throw new ExtensionMalformedCallException('Method not implemented'); } } } public class ExtensionMalformedCallException extends Exception {} public Map getMergeFieldMapExample1(String recordId) { Opportunity opp = [SELECT Id FROM Opportunity WHERE Id=:recordId]; // Base Object Record Map mergeFieldMapExample = new Map{ 'Field_1' => 'Value_1', 'Field_2' => 'Value_2', 'Field_3' => 'Value_3' }; return mergeFieldMapExample; } } ``` -------------------------------- ### DOCX Named Queries Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/upload-templates-from-microsoft-word-with-the-docx-feature Shows the conversion of named queries from SOQL format to the required DOCX template syntax. This enables the use of named queries within DOCX documents for data retrieval. ```DOCX Syntax {{!myQuery1.fieldname}} ``` ```DOCX Syntax [{{! ... }}] [{{!myQuery1.fieldname}}] ``` ```DOCX Syntax {{!myQuery1.fieldname}} ``` ```DOCX Syntax [{{! ... }}] [{{!myQuery1.fieldname}}] ``` -------------------------------- ### Related List with Row Coloration (tablerow) and New Row for Body Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/specify-color-on-even-odd-rows-in-a-subquery This snippet demonstrates configuring a related list where each record's body is placed in a new row. The 'tablerow' coloration applies alternating row colors for every other table row, and 'newrow="true"' ensures the body content starts on a fresh row. ```xml table876 feeds tablerow SELECT createdby.name, Body, createdby.phone, (SELECT createdby.name, createdby.phone,CommentBody FROM FeedComments) FROM FeedItem WHERE ParentId = '{{!ObjectID15}}' ORDER BY createddate desc createdby.name createdby.phone body sub.FeedComments.createdby.name sub.FeedComments.createdby.phone sub.FeedComments.CommentBody ``` -------------------------------- ### SOQL for Table with New Rows Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/specify-color-on-even-odd-rows-in-a-subquery This SOQL query and associated XML configuration define how to fetch and display feed items and their comments in a table. It includes settings for creating new rows for specific columns, enabling dynamic row coloration based on data. Dependencies include the Salesforce Object Query Language (SOQL) and a custom table class. ```xml table876 feeds SELECT createdby.name, Body, createdby.phone, (SELECT createdby.name, createdby.phone,CommentBody FROM FeedComments) FROM FeedItem WHERE ParentId = '{{!ObjectID15}}' ORDER BY createddate desc createdby.name createdby.phone body sub.FeedComments.createdby.name sub.FeedComments.createdby.phone sub.FeedComments.CommentBody ``` -------------------------------- ### Export S-Docs Templates with SOQL Filter (Base Object and Ordering) Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/moving-templates-from-sandbox-to-production This example demonstrates exporting S-Docs templates related to a specific base object, ordered by creation date, and limited to a specific number of results. This is useful for retrieving the most recent templates for a given object. ```plaintext WHERE Base_Object__c='Opportunity' ORDER BY CreatedDate DESC LIMIT 5 ``` -------------------------------- ### Substitute for Numeric Precision Matching Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/advanced-template-features Shows an example of using the 'substitute' attribute for numeric fields, emphasizing the need to match the precision of the numeric value for a successful substitution. ```xml quantity ``` -------------------------------- ### PDF Document Generation & S-Docs Email SDK Source: https://kb.sdocs.com/knowledge-base/sdocs/generating-documents/s-docs-software-development-kit-documentsdk This section details the methods available for generating PDF documents and emails using the S-Docs SDK. It covers supported contexts, use cases, usage examples, method signatures, parameters, and return types. ```APIDOC ## PDF Document Generation & S-Docs Email SDK ### Description Provides methods to generate PDF documents and emails using S-Docs Templates. This SDK simplifies the process of creating and distributing documents and emails from within organizational applications. ### Supported Contexts - Apex Invocable Class (that can be called from a Flow) - Apex Queueable - Apex Batch - **@future** Apex method - Visualforce Apex Controller (Custom and Controller extensions) - **AuraEnabled** Apex method - Apex class that supports an OmniScript **Note**: Apex trigger context is not supported and will result in an Exception being thrown. ### Use Cases - Generate a document in batch from an existing Apex Batch or Apex Queueable class - Generate a document from an existing UI component: Aura or Lightning Web Component - Generating a document from a custom Visualforce page - Generating a document from an OmniScript ### Usage Invoke the SDK method in your Apex class (Lightning Web component controller, Apex invocable, Queueable or Apex batch classes) as follows: ```apex String jsonResp = SDOC.DocumentSDK.generateDocument('','recordId'); Map respAsObject = JSON.deserialize(jsonResp, Map.class); ``` ### Methods #### `generateDocument(Id templateId, Id recordId)` ##### Description Generates a document using the specified template and base record. ##### Method Signature `generateDocument(templateId, recordId)` ##### Parameters - **templateId** (Id) - Required - The ID of the template used for generating the document. - **recordId** (Id) - Required - The ID of the base record object. ##### Returns - **Type**: ID (SDOC_SDoc_c) - Description: Document information associated with the generated PDF in JSON format. #### `generateDocument(Id templateId, Id recordId, GenerationOptions generationOptions)` ##### Description Generates a document using the specified template and base record, allowing for additional custom options. ##### Method Signature `generateDocument(Id templateId, Id recordId, GenerationOptions generationOptions)` ##### Parameters - **templateId** (Id) - Required - The ID of the template used for generating the document. - **recordId** (Id) - Required - The ID of the base record object. - **generationOptions** (GenerationOptions) - Optional - Allows for additional custom options during document generation. ##### Returns - **Type**: Map - Description: Information about the Generated Document returned as a map. **Available in**: S-Docs September '23 (v5.0) and above for the overload without `generationOptions`. S-Docs May'24 (v7.1) and above for the overload with `generationOptions`. ``` -------------------------------- ### DOCX Line Items Table Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/upload-templates-from-microsoft-word-with-the-docx-feature Defines the structure for displaying line items from opportunitylineitems in a DOCX template. It requires a table format with specified columns and formatting for currency. ```DOCX Syntax [{{! ] //Your Table Here [ opportunitylineitems name quantity listprice totalprice }}] ``` ```DOCX Syntax [{{! ] //Your Table Here [ opportunitylineitems name quantity listprice totalprice }}] ``` -------------------------------- ### Export S-Docs Templates with SOQL Filter (Template Name) Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/moving-templates-from-sandbox-to-production This example demonstrates using the SOQL LIKE operator to export S-Docs templates whose names contain a specific string. This is useful for exporting templates with similar naming conventions. ```plaintext WHERE Name LIKE '%Master Service Agreement%' ``` -------------------------------- ### Re-display Quantities and Product Codes Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/the-named-query-feature This example shows the reusability of named queries within a template by displaying quantities and product codes again. It reinforces the concept that once a query is named, its results can be referenced multiple times throughout the S-Doc template without needing to re-execute the SOQL. ```html And let's just put the quantities and product codes here again, just because we can: {{!myQuery1.quantity}} | {{!myQuery1.productcode}} {{!myQuery2.quantity}} | {{!myQuery2.productcode}} ``` -------------------------------- ### Dynamic Component Reference Example in S-Docs Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic/using-dynamic-components-references-in-s-docs This snippet demonstrates how to use dynamic component references in S-Docs for Salesforce, allowing templates to dynamically pull in data based on Salesforce fields, such as the opportunity's language. It shows conditional rendering based on language to include specific components. ```sdocstemplate {{!BaseObject.Field}} {{Opportunity.lp_language_c}} == 'English' --> {{{{!Proposal Pricing Sheet English Component}}}} {{{{!Proposal Pricing Sheet {{!Opportunity.language}} Component}}}} ``` -------------------------------- ### S-Docs Conditional Logic Syntax Example Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic/insert-conditional-logic-button This snippet demonstrates the basic syntax for conditional rendering in S-Docs. It shows how to define a condition using merge fields and operators, and the content to be displayed if the condition is true. The '' and '' tags enclose the conditional block. ```text This contact has phone information available. Their mobile number is {{!Contact.mobilephone}} and their business number is {{!Contact.phone}}. ``` -------------------------------- ### Generate PDF Document with S-Docs SDK (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/generating-documents/s-docs-software-development-kit-documentsdk This method generates a PDF document using a specified S-Docs template and a base record. It can be invoked from various Apex contexts. The method returns the ID of the generated S-Doc record and information in JSON format. Ensure you have S-Docs v5.0 or later installed. ```Apex String jsonResp = SDOC.DocumentSDK.generateDocument('','recordId'); Map respAsObject = JSON.deserialize(jsonResp, Map.class); ``` -------------------------------- ### Apex Test Class for 'No Contact Record' Trigger Source: https://kb.sdocs.com/knowledge-base/sdocs/installation/sdocs-quick-install-configuration-guide-salesforce-lightning This Apex test class provides the necessary test coverage for the 'No Contact Record' trigger. It simulates the creation of a Contact with the LastName 'No Contact Record' to ensure the trigger functions correctly when S-Docs attempts to create this record. This is crucial for maintaining code quality and deployment readiness. ```apex @isTest private class NoContactTestClass { @isTest public static void noContactTest() { Test.startTest(); Contact testContact = new Contact(); testContact.LastName = 'No Contact Record'; insert testContact; Test.stopTest(); }} } ``` -------------------------------- ### Update S-Doc Page Layout in Salesforce Source: https://kb.sdocs.com/knowledge-base/sdocs/general-configuration/download-sdocs-upgrades This example demonstrates how to add the 'Allow Edit' field to an S-Doc template page layout in Salesforce. It assumes the latest version of S-Docs is installed and involves navigating through the Salesforce Object Manager. ```text Navigate to Setup. Go to Object Manager. Find and click on your object (e.g., S-Doc Template). Navigate to the Page Layouts tab. Click Edit for the appropriate page layout. In the Fields tab, find the 'Allow Edit' field. Drag the 'Allow Edit' field to the desired area in your page layout. Click Save. ``` -------------------------------- ### Conditional Logic: Handling Null Phone Numbers (S-Docs) Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic-sdocs/overview-conditional-logic This example shows how to display different messages based on whether a Contact's phone number is NULL or not. It uses two S-Docs Render blocks, one for the NULL condition and one for the non-NULL condition, employing equality and inequality comparators. ```sdocs No Phone Number on recode. Please update. We have the following phone number: {{!contact.phone}} ``` -------------------------------- ### Update DOC/DOC-NEW Template Image URLs Source: https://kb.sdocs.com/knowledge-base/sdocs/administration/considerations-enhanced-domains-with-s-docs This example outlines the process for updating image URLs in DOC/DOC-NEW S-Docs templates when images are stored in the local org. It involves extracting the image ID from the template source, constructing a temporary URL to access the Salesforce Documents record, copying the new image address, and pasting it into the image SRC tag. ```text Find the image ID in your DOC/DOC-NEW template source. Paste the image ID into your browser URL after "lightning.force.com/" (e.g., https://YourMyDomainName.lightning.force.com/01Zxxxxxxxxxxxx/e?retURL=%2F006&lightning:force.com/01Zxxxxxxxxxxxx/e?retURL=%2F006). Right-click on the image and click "Copy Image Address". Paste the new image URL into the image SRC tag in your template source. ``` -------------------------------- ### SOQL for Table without New Rows Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/specify-color-on-even-odd-rows-in-a-subquery This SOQL query and XML configuration define table data display without forcing new rows for the body content. It's suitable for displaying feed items and comments in a more compact table format, with row coloration still enabled. Dependencies include SOQL and a custom table class. ```xml table876 feeds SELECT createdby.name, Body, createdby.phone, (SELECT createdby.name, createdby.phone,CommentBody FROM FeedComments) FROM FeedItem WHERE ParentId = '{{!ObjectID15}}' ORDER BY createddate desc createdby.name createdby.phone body sub.FeedComments.createdby.name sub.FeedComments.createdby.phone ``` -------------------------------- ### Basic UILanguage Parameter Example Source: https://kb.sdocs.com/knowledge-base/sdocs/general-configuration/translate-the-s-docs-ui A simple example of the 'UILanguage' parameter, which is added to the S-Docs button URL to set the user interface language. This is a basic representation of the parameter itself. ```plaintext UILanguage='Spanish' ``` -------------------------------- ### Basic Switch Statement Syntax in S-Docs Templates Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic/use-switch-statements This code snippet demonstrates the fundamental structure of a switch statement in S-Docs templates. It includes the main switch tag, the switch map template name, the rendering formula, and the output for matching values. Ensure this is written within the 'Source' view of the template editor. ```html ``` -------------------------------- ### Offset Starting Row Number in Table Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/customizing-your-related-list-layout This snippet shows how to offset the starting row number in a related list table by adding the 'startIndex' attribute to the 'rownum' tag. This allows row numbers to begin at a specified number other than 1. ```XML rownum ``` ```XML table646 opportunitylineitems rownum PricebookEntry.Product2.name PricebookEntry.Product2.description unitprice quantity totalprice ``` -------------------------------- ### Generate S-Doc With Input Apex Action Source: https://kb.sdocs.com/knowledge-base/sdocs/generate-documents-automatically/invocable-apex-action-library-for-flow-builder Generates S-Docs by incorporating real-time user inputs, designed for integration with Salesforce screen flows. Supports Guest User generation in Experience Cloud (v9.0+). ```apex apex-SDOC__UserInputInvocable ``` -------------------------------- ### Combine Documents Handler Apex Source: https://kb.sdocs.com/knowledge-base/sdocs/generate-documents-automatically/invocable-apex-action-library-for-flow-builder Handles the combining of multiple documents into a single compiled PDF file. This functionality is available starting with the S-Docs May '24 release. ```apex apex-SDOC.CombinedDocumentHandler() ``` -------------------------------- ### Salesforce Flow: Get Records Element Source: https://kb.sdocs.com/knowledge-base/ssign/send-and-track-e-signature-requests/configuring-a-salesforce-flow-for-s-docs-s-sign-workflows This Flow element retrieves records, such as Opportunity records, from Salesforce. It is configured to gather specific records that will be displayed in a screen element. ```flow-get-records { "element": "Get Records", "object": "Opportunity", "filter": {}, "sort": {}, "storeRecords": true } ``` -------------------------------- ### S-Docs Arithmetic Function Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic-sdocs/using-arithmetic-functions Demonstrates the basic syntax for using arithmetic functions within S-Docs templates. Supports static numbers and Salesforce merge fields. Enclosed in tags and follows Salesforce math operators and order of operations. ```S-Docs Template (2 + 1) / 3 ( {{!Opportunity.Num1__c}} + {{!Opportunity.Num2__c}} ) / {{!Opportunity.Num3__c}} ``` -------------------------------- ### Display Shipping Contact Merge Fields Source: https://kb.sdocs.com/knowledge-base/sdocs/merge-fields/merge-shipping-billing-contacts-at-runtime These merge fields display various contact details for the shipping contact. They are placeholders that get populated with actual data when a document is generated. ```template {{!PICKLIST.shippingContact.name}} {{!PICKLIST.shippingContact.firstname}} {{!PICKLIST.shippingContact.lastname}} {{!PICKLIST.shippingContact.email}} {{!PICKLIST.shippingContact.phone}} {{!PICKLIST.shippingContact.title}} ``` -------------------------------- ### Base S-Docs Template Editor URL Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/hide-template-editor-tabs This is the base URL for the S-Docs template editor, used as a starting point for customization. It requires the record ID and a field reference. ```apex {!URLFOR('/apex/SDOC__SDTemplateEditor', null,[Id=SDOC__SDTemplate__c.Id,Field='Template_XML__c'])} ``` -------------------------------- ### Swap Placeholders in HTML String (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/add-dynamic-tables-of-contents-to-doc-templates This utility method takes an HTML string and a list of replacement strings. It iterates through the list, replacing placeholders in the format '{index}' with the corresponding string from the list. This is useful for dynamically populating HTML templates. ```Apex public static String swapFields(String toSwap, List replacements) { for (Integer i = 0; i < replacements.size(); i++) { toSwap = toSwap.replace('{' + i + '}', replacements[i]); } return toSwap; } ``` -------------------------------- ### Create S-Sign Envelope using Apex Source: https://kb.sdocs.com/knowledge-base/ssign/create-and-manage-ssign-templates/s-sign-software-development-kit-esignsdk This Apex code demonstrates how to prepare an S-Sign envelope by providing a list of SDOC document IDs. The 'prepareEnvelope' method is used to initiate the envelope creation process. It returns the ID of the newly created SSign_SSEnvelope__c record. Ensure that only one invocation of 'prepareEnvelope' or 'sealEnvelopeAndGetSigningLink' occurs per Apex transaction to avoid a LimitsException. ```apex List sDocIdsInEnvelope = new List(); sDocIdsInEnvelope.add('...SDOC__SDOC__c.Id...'); sDocIdsInEnvelope.add('...SDOC__SDOC__c.Id...'); String ssign__SSEnvelope_Id = SDOC.ESignSDK.prepareEnvelope(sDocIdsInEnvelope); ``` -------------------------------- ### S-Docs Component with Page Break Delimiter Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/generate-a-component-template-for-each-record-in-a-related-list This example demonstrates how to configure components to separate merged content with page breaks using the `delimiter` attribute. This is useful for organizing generated documents. ```html Component Name Component Name ``` -------------------------------- ### One-Click Email Preparation with S-Docs Source: https://kb.sdocs.com/knowledge-base/sdocs/generate-documents-automatically/automation-options-improving-efficiency-and-compliance Configures an S-Docs button to prepare an email with generated documents as attachments, allowing user review before sending. Requires an HTML template in the doclist for the email body. Uses the 'prepemail='1'' parameter. ```Salesforce Apex {!URLFOR('/apex/SDOC__SDCreate1', null,[id=Opportunity.Id, Object='Opportunity', doclist='Email_Template,Template_1', prepemail='1'])} ``` -------------------------------- ### Format Product Data with Callable Apex (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/applying-logic/call-apex-classes-in-your-s-docs-templates This Apex code snippet demonstrates how to format product data, including description and code, within an S-Docs template using a callable Apex method. It assumes a structure where product information is being aggregated. The output is a string containing XML-like product data. ```Apex + '  Green fruit' + '  3012' + ''; } } ``` ``` -------------------------------- ### Apex: Upload Document to Box Source: https://kb.sdocs.com/knowledge-base/sdocs/integrations/integrating-s-docs-with-box This Apex code snippet demonstrates the process of creating an attachment, setting the current Visualforce page, and invoking the Box upload controller to upload a document to Box. It requires the SDoc and Box integration to be set up. ```apex Blob body = Blob.valueOf('test'); ParentId = sdoc.Id; ) insert att; Test.setCurrentPage(Page.SDOC__SDCreate3); ApexPages.currentPage().getParameters().put('sdocId', sdoc.Id); ApexPages.currentPage().getParameters().put('attId', att.Id); SDBoxUploadController sdbuc = new SDBoxUploadController(); sdbuc.uploadToBox(); ``` -------------------------------- ### DOCX Render Statements Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/upload-templates-from-microsoft-word-with-the-docx-feature Illustrates how to use render statements in DOCX templates for conditional content display. It allows for rendering content based on boolean expressions or field value comparisons. ```DOCX Syntax [] [{{!Contact.Name}}] can be reached at [{{!Contact.Phone}}]. This is never true. [] [] [{{!Contact.Name}}] can be reached at [{{!Contact.Phone}}]. This may or may not be true. [] [] This is always true. [] [] This is never true. [] ``` ```DOCX Syntax [] [{{!Contact.Name}}] can be reached at [{{!Contact.Phone}}]. This is never true. [] [] [{{!Contact.Name}}] can be reached at [{{!Contact.Phone}}]. This may or may not be true. [] [] This is always true. [] [] This is never true. [] ``` -------------------------------- ### Substitute for Month Name Translation Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/advanced-template-features Provides a practical example of using the 'substitute' attribute to translate numeric month values into their full month names. This includes a catch-all value for any unrecognized month numbers. ```xml MonthNumber__c ``` -------------------------------- ### Swap Placeholders in String (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/add-dynamic-tables-of-contents-to-doc-templates This utility method takes a string and a list of replacement strings, iterating through the list to substitute placeholders in the format '{index}' within the input string. It's used here to dynamically populate custom TOC templates. ```apex public static String swapFields(String toSwap, List replacements) { for (Integer i = 0; i < replacements.size(); i++) { toSwap = toSwap.replace('{' + i + '}', replacements[i]); } return toSwap; } ``` -------------------------------- ### Query Site Guest User Profiles with SOQL Source: https://kb.sdocs.com/knowledge-base/ssign/install-configure-ssign/troubleshooting-s-sign This SOQL query retrieves the Name and Id of users whose names contain 'Site Guest'. This is useful for identifying and managing permissions for Site Guest User profiles, particularly in the context of S-Sign users. ```soql SELECT Name, Id FROM User WHERE Name LIKE '%Site Guest%' ``` -------------------------------- ### Export S-Docs Templates with SOQL Filter (Document Category) Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/moving-templates-from-sandbox-to-production This example demonstrates how to use a SOQL WHERE clause to filter S-Docs templates for export based on the 'Document_Category__c' field. This allows for selective export of templates. ```plaintext WHERE Document_Category__c='Contract' ``` -------------------------------- ### Test TOC and TOF Retrieval (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/add-dynamic-tables-of-contents-to-doc-templates Provides Apex test methods to verify the functionality of a 'TOCCallableClass'. The test methods instantiate the class, call its 'call' method with 'getTOC' argument, and assert that the returned map contains the expected hardcoded HTML strings for TOC and TOF. This tests the correct retrieval of these elements. ```apex @isTest public static void testGetTOCCall() { TOCCallableClass tocClass = new TOCCallableClass(); Map getTOCReturn = (Map) tocClass.call('getTOC', null); System.assertEquals(hardcodedTOCExpected, getTOCReturn.get('TOC')); System.assertEquals(hardcodedTOFExpected, getTOCReturn.get('TOF')); } @isTest public static void testGetTOCCustomCall() { Map args = new Map{ ``` -------------------------------- ### Combined PDF-Upload Component Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/create-component-templates This example combines both the merge field and template syntax for inserting a PDF-Upload component. It's crucial to ensure correct attribute usage and template structure for successful integration. ```Mixed Syntax {{{!PDF Upload Component componentType="pdf-upload"}}}} ``` -------------------------------- ### Custom Table Generation with Prefixes and Postfixes Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/customizing-your-related-list-layout This snippet shows how to use S-Docs' column prefix and postfix attributes to manually define HTML structure for table rows and cells. It allows for custom HTML insertion around data fields like product name, description, unit price, quantity, and total price. This method provides granular control over the table's appearance. ```html
``` -------------------------------- ### Apex Test Class Stub for TOCCallable Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/add-dynamic-tables-of-contents-to-doc-templates This is a basic structure for an Apex test class designed to test functionality related to Tables of Contents (TOC) and Tables of Figures (TOF). It provides a starting point for writing comprehensive unit tests. ```Apex @isTest private class TOCCallableTest { } ``` -------------------------------- ### SOQL Query for Related Records in S-Docs (Method 1) Source: https://kb.sdocs.com/knowledge-base/sdocs/related-lists-and-soql-queries/generate-a-component-template-for-each-record-in-a-related-list This S-Docs template syntax uses the LineItemsSOQL tag to query related records (e.g., Opportunities related to an Account) and specify a component template to render each record's data. It's suitable for shorter lists as it runs a SOQL query for each component. Dependencies include S-Docs for Salesforce. ```text ``` -------------------------------- ### Offset Row Numbering with startIndex - Template Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/advanced-template-features The 'startIndex' attribute allows you to specify an offset for the starting row number when using the 'rownum' column. The actual numbering begins at the value of 'startIndex' plus one. ```template ``` ```template table646 opportunitylineitems rownum PricebookEntry.Product2.name PricebookEntry.Product2.description unitprice quantity totalprice ``` -------------------------------- ### DOCX Rich Text Image Syntax Source: https://kb.sdocs.com/knowledge-base/sdocs/creating-templates/upload-templates-from-microsoft-word-with-the-docx-feature Demonstrates how to display images stored in rich text fields within DOCX templates. It uses triple curly braces to denote rich text merge fields. ```DOCX Syntax [{{{Object.FieldName}}}] ``` ```DOCX Syntax [{{{Object.FieldName}}}] ``` -------------------------------- ### Export S-Docs Templates with SOQL Filter (IN Operator) Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/moving-templates-from-sandbox-to-production This example uses the SOQL IN operator to export S-Docs templates whose names are within a specified list. This is an efficient way to export multiple templates by their exact names. ```plaintext WHERE Name IN ('Invoice','Standard Invoice','Invoice - By Product') ``` -------------------------------- ### Generate PDF Document with S-Docs SDK Options (Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/generating-documents/s-docs-software-development-kit-documentsdk This method generates a PDF document using a specified S-Docs template, a base record, and custom generation options. It allows for more advanced control over document creation. This feature is available in S-Docs May '24 (v7.1) and above. It returns information about the generated document as a map. ```Apex String jsonResp = SDOC.DocumentSDK.generateDocument('', 'recordId', generationOptions); Map respAsObject = JSON.deserialize(jsonResp, Map.class); ``` -------------------------------- ### S-Docs Button URL with One-Click Feature Source: https://kb.sdocs.com/knowledge-base/sdocs/general-configuration/configure-sdocs-with-custom-objects-salesforce-lightning This Salesforce formula enables the 'one-click' S-Docs feature, allowing automatic generation of specified templates without user interaction. The 'doclist' parameter takes a comma-separated list of template API names. ```Salesforce Formula {!URLFOR('/apex/SDOC__SDCreate1', null,[id=CustomObj__c.Id, Object='CustomObj__c', doclist='Template1,Template2'])} ``` -------------------------------- ### Initiate a New Row Based on Value Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/advanced-template-features The 'newrow' attribute controls when a new row should begin. Setting it to 'true' starts a new row for each record, while a numeric value specifies the record number after which a new row is created. ```XML ``` -------------------------------- ### S-Docs Document Generation Parameters Source: https://kb.sdocs.com/knowledge-base/sdocs/generating-documents/s-docs-software-development-kit-documentsdk Defines the parameters for the generateDoc method, including template ID, record ID, generation options, document options, user inputs, email options, and action configurations. These parameters control the document creation process. ```apex templateId | (Type: Id): The ID of the template used for generating the document. recordId | (Type: Id): The ID of the base record object. generationOptions | (Type: SDOC.GenerationOptions) documentOptions | (Type: SDOC.DocumentOptions) userInputs | (Type: SDOC.UserInput) emailOptions | (Type: SDOC.EmailOptions) template | (Type: String) sObjectId | (Type: Id) toAddresses | (Type: List) ccAddresses | (Type: List) bccAddresses | (Type: List) replyToEmail | (Type: String) orgWideEmailAddressId | (Type: Id) emailSubject | (Type: String) sdocIdsToAttach | (Type: List) contentVersionsIdsToAttach | (Type: List) actions | (Type:SDOC.Action) name | (Type: String) parameters | (Type: Map) overrideActions | (Type: Boolean) skipFileSave | (Type: Boolean) ``` -------------------------------- ### Generate Document Apex Action Source: https://kb.sdocs.com/knowledge-base/sdocs/generate-documents-automatically/invocable-apex-action-library-for-flow-builder Generates PDF documents from a base record using a configured S-Docs template. Supports component templates with related lists and Guest User generation in Experience Cloud (v9.0+). ```apex apex-SDOC__GenerateDocumentInvocable ``` -------------------------------- ### Hide Specific Template Editor Tabs Source: https://kb.sdocs.com/knowledge-base/sdocs/managing-templates/hide-template-editor-tabs Append parameters like 'showTabN='false'' to the base URL to hide specific tabs in the S-Docs template editor. For example, 'showTab6='false'' hides the 'Email Settings' tab. ```apex {!URLFOR('/apex/SDOC__SDTemplateEditor', null,[Id=SDOC__SDTemplate__c.Id,Field='Template_XML__c', showTab6='false'])} ``` -------------------------------- ### Generate S-Docs Document URL (Salesforce Apex) Source: https://kb.sdocs.com/knowledge-base/sdocs/general-configuration/configure-sdocs-with-salesforce-quotes This code snippet generates the URL for the S-Docs document creation page for a Quote object. It utilizes the URLFOR function in Salesforce Apex to construct the URL, passing the Quote ID and specifying the object as 'Quote'. This is the standard URL for initiating document creation. ```Salesforce Apex {!URLFOR('/apex/SDOC__SDCreate1', null,[id=Quote.Id, Object='Quote'])} ``` -------------------------------- ### Add S-Sign Licenses to Active Users - Apex Source: https://kb.sdocs.com/knowledge-base/ssign/install-configure-ssign/s-sign-quick-install-salesforce-lightning-experience This Apex code snippet demonstrates how to add S-Sign licenses to all active users in an organization. It first queries for active users, collects their IDs into a List, and then calls the addSSignUserLicenses function to assign the licenses. This function is part of the SSIGN.SSLicensesController. ```apex List userIds = new List(); List activeUsers = [SELECT Id FROM User WHERE isActive = true]; for (User activeUser : activeUsers) { userIds.add(String.valueOf(activeUser.Id)); } SSIGN.SSLicensesController.addSSignUserLicenses(userIds); ``` -------------------------------- ### CSS for Alternating Row Colors in Salesforce Tables Source: https://kb.sdocs.com/knowledge-base/sdocs/formatting-data/specify-color-on-even-odd-rows-in-a-subquery This CSS defines styles for a custom table with the class 'table876'. It includes styles for headers, footers, subheaders, and specifically for alternating row colors ('table876RowEven' and 'table876RowOdd') and sub-rows. This is used to visually distinguish records in a related list. ```css table.table876 {border:solid black 1px; border-collapse:collapse; border-spacing:0px;font-family:Arial,Helvetica,sans-serif; font-size:10pt; width:100% } .table876header {text-align:center;border:solid black 1px;color:#FFFFFF;background-color:#000000;} .table876footer {text-align:right;font-weight:bold;border:solid black 1px; height: 30px} .table876subheader {text-align:center;font-weight:bold;border:solid black 1px;color:#FFFFFF;background-color:#000000;} .table876RowEven{border:solid black 1px;background-color:#2ecc71;} .table876RowOdd{background-color:#cdcdcd;border:solid black 1px;} .table876subRowEven{border:solid black 1px;background-color:#f1c40f;} .table876subRowOdd{background-color:#8e44ad;border:solid black 1px;} .table876col0{border:solid black 1px;text-align:left;} .table876col1{border:solid black 1px;text-align:left;} .table876col2{border:solid black 1px;text-align:left;} .table876col3{border:solid black 1px;text-align:left;} .table876col4{border:solid black 1px;text-align:left;} .table876col5{border:solid black 1px;text-align:left;} ```