Loading
Salesforce Document Generation
Example: Generating a Contract Document by Using Context Service

Example: Generating a Contract Document by Using Context Service

Understand how Context Service can streamline contract document generation by mapping structured Salesforce data to template tokens. This setup supports dynamic content, hyperlinks, images, and live updates using a reusable context definition and mapping. Review the context definition structure, mapping, and JSON output that illustrate how Context Service can support contract document generation. It includes elements such as dynamic content, hyperlinks, images, and live updates by using a reusable context definition.

Required Editions

Available in: Lightning Experience
Available in: Professional, Enterprise, Unlimited, and Developer Editions

A contract author needs to generate a customer-specific contract that includes account details, key dates, rich formatting such aslogos and hyperlinks, and editable status fields. Context Service makes this possible without Apex or custom data mappers.

Context Definition Structure

This table shows example nodes, attributes, and their purposes when defining a context structure for contract documents.

Node Attribute Purpose
Contract StartDate Show contract start date
Contract DT_Status Allow editable contract status
Contract Name Show customer account name
Contract BillingCity Include city in billing address
Contract IMG_CompanyLogo_src (image) Embed company logo
Contract HYP_TermsLink (hyperlink) Add terms and conditions link
Context definition mapping to generate a contract document.

Context Mapping Example

Context mapping to generate a contract document.
Context Attribute Mapped Field in Salesforce Token Format in Template
StartDate Contract.StartDate {{StartDate}}
DT_Status (True-up) Contract.Status {{DT_Status}}
Acccount_Name Contract.Account.Name {{Account_Name}}
Billing_City Contract.Account.BillingCity {{Billing_City}}
IMG_CompanyLogo_src (Image) Contract.CompanyLogoFileName {{IMG_CompanyLogo}}
HYP_TermsLink_url(Hyperlink) Contract.TermsURL {{HYP_TermsLink}}
HYP_TermsLink_text (Hyperlink Label) Contract.TermsText {{HYP_TermsLink}}

Sample JSON Output

{
  "StartDate": "2025-08-01",
  "Name": "Acme Corporation",
  "Billing_City": "San Francisco",
  "IMG_CompanyLogo": {
    "src": "0697x00000XYZ123"
  }
},
  "HYP_TermsLink": {
    "url": "https://acme.com/terms",
    "text": "View Terms"
  },
  "DT_Status": {
    "objectId": "8007x00000ABC456",
    "objectName": "Contract",
    "fieldName": "Status",
    "fieldValue": "Draft"
  }
}
Note
Note To use this context definition in a Document Generation Process (DGP), set Additional Input Type to Context Service and enter the Contract record ID as the Additional Input. This links the document generation process to the correct contract.
 
Cargando
Salesforce Help | Article