Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.

Explore Server-Side Document Generation

Learning Objectives 

After completing this unit, you’ll be able to:

  • Describe the benefits and capabilities of server-side document generation.
  • Identify when to use server-side document generation.
  • Customize out-of-the-box samples for a faster implementation.

A Different Approach to Generating Documents

Traditionally, document generation has been a browser-based process, taking place on the client machine. User interaction was often required to generate documents and convert them into PDFs. This process generally works well for Sophia’s team and the many documents they need to create.

Felix and Sophia discuss areas of improvement for document generation processes.

However, some documents need a different approach. The team generates some very large contracts that take ages to process. Also, some documents don’t need team input, so their generation can be automated. Felix notices these inefficiencies and decides to implement server-side document generation. 

Server-Side Document Generation Capabilities

You can do a lot with server-side document generation. Before we follow Felix on his next journey, let’s examine some benefits and capabilities.

  • Automate document generation with APIs. Generate documents using APIs, without the need for user input. Configure your OmniScript to call APIs to perform server-side document generation, independent of the browser client.
  • Launch document generation from multiple sources. Launch server-side document generation in different ways. For example, use back-end Apex code, Integration Procedures, or OmniScripts.
  • Generate large documents and multiple documents in a batch. Server-side document generation works great for rendering heavy documents with a large amount of data because it uses Salesforce compute resources instead of browser resources. It also supports batch processing to generate multiple documents at the same time.
  • Implement solutions faster with sample assets. To get up to speed fast, Industries Document Generation provides several assets you can use as a starting point to set up your solution. The assets include a sample Integration Procedure, server-side OmniScript, and a Lightning web component.

When to Use Server-Side Document Generation

But when is the right time to use server-side document generation?

  • A document is rendering heavy. For example, the document has many tokens, heavy tabulation, or a large number of lines. Infiwave enterprise customer contract documents fit this profile because the orders are generally large, and the documents must pull in a hefty amount of data.
  • Several documents require batch-processing. For example, a salesperson wants to generate a multisite quote document for custom products for office workers. In this case, each office location requires a separate quote. With server-side document generation, you can generate quote documents for all locations at once.
  • A trigger should generate documents. A trigger can be anything, for example, a record status change. Sophia's team needs to generate and send several reports to her. With server-side document generation, they can save a lot of time. For example, whenever an opportunity status changes to Closed-Won, an opportunity report can be automatically generated and attached to the opportunity record.

Document Generation Flow

Now let’s look at what’s happening under the hood with server-side document generation flow. Here’s a diagram that shows the process.

A diagram that shows server-side document generation flow

In the diagram, the document-generation process launches from an Integration Procedure, an OmniScript, or Apex code. This generates a BPO (Base Platform Object) request that goes into a queue. The process can generate several BPO requests at once, which wait in the queue until dequeuing mechanisms call remote APIs. The remote API methods run on Hyperforce, which dedicates Salesforce compute resources to the process. The methods pull requests from the queue and generate documents. Once the documents are generated, they’re stored in Salesforce as content documents.

Implement Server-Side Document Generation Faster

Salesforce wants you to roll out your solution fast. That’s why you have several assets to use as a starting point for your projects. Server-side document generation also starts with document template creation. 

Let’s see the assets Felix uses to get started.

Sample OmniScript

The Industries Document Generation package comes with a sample server-side OmniScript named docGenerationSample/SingleDocxServersideLwc. Felix uses this sample as a basis for a multi-site quoting template for documents that Infiwave needs to generate for large customers. Felix makes a new version of the sample and gets to work.

Sample Integration Procedures

The Industries Document Generation package also includes sample Integration Procedures. Each sample invokes different methods of Apex classes and generates a Microsoft Word, Microsoft PowerPoint, or PDF document. The Integration Procedures can also convert previously generated .docx or .pptx files to PDF. The output document format depends on the input parameters specified in the Integration Procedure.

Server-Side Document Generation OmniScript Sample

Felix uses the sample OmniScript to create document generation processes for the Infiwave sales team. You can use the sample to test your template or as a starting point for building your own OmniScript. Then end users can launch the OmniScript from a record page to generate a document. 

Find the sample OmniScript in the OmniScript tab under the name: docGenerationSample/SingleDocxServersideLwc. 

Felix creates a new version of the sample OmniScript. He uses his version as the starting point for a new document generation OmniScript. This way, the original sample OmniScript is in place, ready to use for any new OmniScripts later on.

Let’s learn about the elements of the OmniScript sample and follow Felix as he customizes it for his use case. The sample server-side document generation OmniScript includes several steps, which run sequentially when the OmniScript is invoked. 

Click the plus-icon (+) hot spots on the image to learn more.

Sample OmniStudio Integration Procedures

Industries Document Generation provides sample OmniStudio Integration Procedures to help you implement server-side document generation. The OmniScript calls the sample Integration Procedures, and you can customize it to use standalone. Each sample invokes different methods of Apex classes to generate a Microsoft Word, Microsoft PowerPoint, or PDF document.

Integration Procedure

Trigger Condition

Output

DocumentServiceGateway_DocGeneration

ServiceFunction value is set to Server-Side Document Generation

Depending on the input parameters specified, you can generate .docx, .pptx, or pdf documents.

DocumentServiceGateway_DocGenerationWithTokenData

ServiceFunction value is set to Server-Side Document Generation w/ Token Data

Depending on the input parameters specified and token data, you can generate .docx, .pptx, or pdf documents.

DocumentServiceGateway_DocGenerationPDF

ServiceFunction value is set to Server-Side PDF Generation

Depending on the previously generated .docx or .pptx document, a pdf document is generated.

Note

Server-side document generation is disabled by default. To enable this feature, see the Request Access to Server-Side Document Generation knowledge article.

Want to Learn More?

If you’re a Salesforce customer, check out the following learning journeys to find out how to skill up on our amazing suite of digital transformation tools and industry applications.

If you’re a Salesforce partner, you’ll find the same great learning plus additional partner resources on Partner Learning Camp (log in required). #AlwaysBeLearning 

Resources 

Teilen Sie Ihr Trailhead-Feedback über die Salesforce-Hilfe.

Wir würden uns sehr freuen, von Ihren Erfahrungen mit Trailhead zu hören: Sie können jetzt jederzeit über die Salesforce-Hilfe auf das neue Feedback-Formular zugreifen.

Weitere Infos Weiter zu "Feedback teilen"