Loading
Omnistudio Document Generation
목차
필터 선택

          결과 없음
          결과 없음
          몇 가지 검색 팁

          키워드의 맞춤법을 확인하십시오.
          더 일반적인 검색 용어를 사용하십시오.
          필터 수를 줄여 검색 범위를 확장하십시오.

          전체 Salesforce 도움말 검색
          Sample Apex Code for Server-Side Document Generation

          Sample Apex Code for Server-Side Document Generation

          Here's a sample code that demonstrates how to generate documents on the server by inserting a DocumentGenerationProcess record. You can generate a document on the server either by directly passing token data, or by sending document template details and letting Salesforce fetch token data automatically.

          Directly Pass Token Data

          Use this approach to when you want to define and control the token values that Salesforce uses during the document generation request. See DocumentGenerationProcess.

          DocumentGenerationProcess documentGeneration = new DocumentGenerationProcess();
          
          documentGeneration.Type = 'GenerateAndConvert';
          
          documentGeneration.RequestText = JSON.serialize(new Map<String, Object>{
          
          'keepIntermediate' => true,
          
          'title' => 'Quote Details',
          
          'templateContentVersionId' => '068Ws00000BXC2aIAH'
          
          });
          
          documentGeneration.ReferenceObject = '001Ws00003FrP4dIAF';
          
          documentGeneration.TokenData = JSON.serialize(new Map<String, String>{
          
          ‘Name => ’John P’,
          
          });
          
          
          documentGeneration.DocGenApiVersionType = 'Advanced';
          
          insert documentGeneration;

          Send Document Template Details to Fetch Token Data Automatically

          Use this approach to automatically resolve token data based on the document template’s configuration. When you use DocumentInputType = DocumentTemplate, Salesforce automatically resolves token data based on the template’s configured data mappings, such as DataRaptor Extracts.

          DocumentGenerationProcess documentGeneration = new DocumentGenerationProcess();
          
          documentGeneration.Type = 'GenerateAndConvert';
          
          documentGeneration.RequestText = JSON.serialize(new Map<String, Object>{
          
          'keepIntermediate' => true,
          
          'title' => 'Quote Details',
          
          'templateContentVersionId' => '068Ws00000BXC2aIAH'
          
          });
          
          documentGeneration.ReferenceObject = '001Ws00003FrP4dIAF';
          
          documentGeneration.DocumentInputType = 'DocumentTemplate';
          
          documentGeneration.DataRaptorInput = '{"Id":"0017Y00001jt9cVQAQ"}'; // Pass ID Which should be the Input ID to the Extract DataMapper 
          
          documentGeneration.DocGenApiVersionType = 'Advanced';
          
          documentGeneration.DocumentTemplateId = '2dtWs000000KELNIA4';
          
          insert documentGeneration;
          
          

          Send Token Data Using a JSON File

          Use this approach when your token data is stored in a JSON file. Upload the JSON file to Salesforce Files, and then set the TokenDataContentDocumentId field on the DocumentGenerationProcess record to the uploaded JSON file’s ContentDocumentId. During server-side document generation, Salesforce reads the JSON from the file and uses it as token data.

          DocumentGenerationProcess documentGeneration = new DocumentGenerationProcess();
          
          documentGeneration.Type = 'GenerateAndConvert';
          
          documentGeneration.RequestText = JSON.serialize(new Map<String, Object>{
          
          'keepIntermediate' => true,
          
          'title' => 'Quote Details',
          
          'templateContentVersionId' => '068Ws00000BXC2aIAH'
          
          });
          
          documentGeneration.ReferenceObject = '001Ws00003FrP4dIAF';
          
           // Uploaded JSON File ContentDocument ID
          
          documentGeneration.TokenDataContentDocumentId  = '069WU00000ImN3BYAV';
          
          documentGeneration.DocGenApiVersionType = 'Advanced';
          
          insert documentGeneration;

          Merge Generated PDFs

          To combine generated PDFs into a single file, use Apex to generate each PDF, and then start a merge request.

          Create a document template in Document Template Designer for each file to merge, and insert a DocumentGenerationProcess record for each template with the relevant object ID, template ID, request text, and token data, as shown in the earlier sections. Capture each PDF's ID from the response field on the record. When all the PDFs are ready, insert a DocumentGenerationProcess record with Type set to MergePDF and the source PDF IDs in PdfDocIdentifiersList, and set ReferenceObject to the record where Salesforce attaches the merged PDF. Alternatively, you can merge any PDFs within Salesforce using the same steps and running the sample apex code below.

          Tip
          Tip You can merge up to 10 PDFs in one request. For document generation limits, see Salesforce Document Generation Hourly and Daily Org Limits.
          String requestText = '{\"title\":\"NewDocDemoTestDevConsole\"}';
          String type = 'MergePDF';
          String pdfDocList = '068SG000000IhrKYAS,068SG000000Imm9YAC';
          DocumentGenerationProcess request = new DocumentGenerationProcess();
          request.Type = type;
          request.RequestText = requestText;
          request.DocGenApiVersionType = 'Advanced';
          request.PdfDocIdentifiersList = pdfDocList;
          insert request;
          
           
          로드 중
          Salesforce Help | Article