Skip to main content

Discover 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 .pdf. This process works great for Candace’s team and the many documents they need to generate. 

Linda and Candace discuss areas of improvement for document-generation processes.

However, some documents need a different approach. The team generates some very large contracts that take a long time to process. Also, some documents don’t need team input, so their generation could be automated. Linda notices 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 Linda on her 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 many different ways. Use a back-end Apex code, Integration Procedures, or OmniScripts.
  • Generate large and multiple documents. 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 generating multiple documents at the same time.
  • Implement solutions faster with sample assets. To get up to speed fast, OmniStudio Document Generation provides several assets you can use as a starting point to customize your use case. The assets include a sample Integration Procedure, a server-side OmniScript, and a Lightning web component.

When to Use Server-Side Document Generation

But when’s the right time to use server-side document generation? Let’s find out about some common situations Linda sees at Cloud Kicks.

  • A document is rendering heavy. For example, the document has many tokens, heavy tabulation, or a large number of lines. Cloud Kicks enterprise customer contract documents fit this profile because the orders are generally large, and the documents pull in a hefty amount of data.
  • Processing multiple documents. For example, you have a multisite quote document that you want to generate and send to customers. Candace works with many enterprise customers who want to order custom sneakers for their office locations, but each location requires a separate quote. With server-side document generation, Candace 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. Candace’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 the opportunity status changes to Closed-Won, an opportunity report can be automatically generated and attached to the opportunity record.

Server-Side 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 services run on the Hyperforce computer environment. 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 Processes 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 Linda uses to get started.

Sample OmniScript

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

Sample Integration Procedures

The OmniStudio Document Generation package also includes sample Integration Procedures. Each sample invokes remote actions 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

Linda uses the sample OmniScript to create document-generation processes for the Cloud Kicks 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/fndSingleDocxServersideLwc. 

Linda creates a new version of the sample OmniScript. She uses her version as the starting point for a new document-generation OmniScript. This way, the original sample OmniScript remains as is, so Linda can use the original sample to create other OmniScripts later on.

Let’s learn about the elements of the OmniScript sample and follow Linda as she customizes it for her use case. 

The sample server-side document-generation OmniScript includes six steps, which run sequentially when the OmniScript is invoked. 

Sample OmniStudio Integration Procedures

Sample OmniStudio Integration Procedures are also provided for quick implementation of server-side document generation. The OmniScript calls the sample Integration Procedures, but you can customize it or use it standalone. Each sample invokes different remote actions 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 isn’t enabled by default. To enable this feature, see the Request Access to Server-Side Document Generation knowledge article.

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities