Loading
Omnistudio Document Generation
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Sample Apex Code for Generating Quotes in Batch

          Sample Apex Code for Generating Quotes in Batch

          Here is a sample of Apex code that carries out two main functions. First, it creates a record named DocGenerateBatchProcess which is responsible for generating quotes. Second, it creates a list of 100 quote documents and links these documents with the DocGenerateBatchProcess record. To start a batch using Apex, update the Status field to InProgress. This value is case sensitive, and the batch runs automatically after the status is updated.

          Create a DocGenerateBatchProcess record for generating quotes

          DocGenerationBatchProcess dgbp = new DocGenerationBatchProcess( Description = 'Generate Quotes in Bulk', Category = 'Quotes');
          insert dgbp;
          

          Create a list of 100 quote documents and associate them with the DocGenerateBatchProcess record

          DocGenerationBatchProcess dgbp = new DocGenerationBatchProcess( Description = 'Generate Quotes', Category = 'Quotes');
          insert dgbp;
          List<DocumentGenerationProcess> dgpList = new List<DocumentGenerationProcess>();
          String quoteId = '0Q0OG0000000Yoc0AE';
          String quoteTemplateContentVersionId = '068OG0000003iy6YAA'; 
          String sampleTokenData = '{"SUBSCRIBER_NAME":"Subname","STREET1":"Panathur","CITY":"Blr","STATE":"KA","POSTALCODE":"494001","COUNTRY":"India"}';
          
          for(Integer i=1; i<=1; i++) {
          	String docTitle = 'Quotes'  + i;
          	DocumentGenerationProcess dgp = new DocumentGenerationProcess (
            		Type = 'GenerateAndConvert', Status = 'InProgress',
          		RequestText='{"keepIntermediate":true, "title":"' + docTitle + '","templateContentVersionId":"'+quoteTemplateContentVersionId+'"}',
            		TokenData = sampleTokenData,
            		ReferenceObject = quoteId, 
            		DocGenApiVersionType='Advanced',
            		DocGenerationBatchProcessId = dgbp.Id
          	);
          	dgpList.add(dgp);
          }
          insert dgpList;
          

          Parameters

          Parameter Description
          DocGenApiVersionType

          Defines the API version that you want to use for document generation. To support rich text and hyperlink tokens for document generation process records, set the Doc Generation API Version Type setting to Advanced.

          docTitle

          Document title.

          quoteId

          ID of the quote.

          quoteTemplateContentVersionId

          Document template content version ID.

          ReferenceObject

          Indicates the object that the generated document is attached to. In the sample Apex code, Account ID is the reference object. The generated document is saved in the Notes and Attachments section of the account.

          requestText
          • templateContentVersionId: Content version ID of the document template that you want to use.

          • title [optional]: Title for the generated document. For example, NewDocDemo.

          • keepIntermediate: When set to true, the system persists with the generated intermediate Word document and the final PDF document.

          Status

          Status of the document generation batch process request: Canceled, Completed, In Progress, New, or Paused.

          templateContentVersionId

          ID of the document associated with the batch process.

          TokenData

          Stores the JSON key-value pair that's used as an input for server-side document.

          Type

          GenerateAndConvert: Generates a Word document and creates a PDF document.

           
          Loading
          Salesforce Help | Article