Loading
Salesforce Document Generation
Sisällysluettelo
Valitse suodattimet

          Ei tuloksia
          Ei tuloksia
          Tässä on joitain hakuvinkkejä

          Tarkista avainsanojesi oikeinkirjoitus.
          Käytä yleisempiä hakutermejä.
          Laajenna hakua valitsemalla vähemmän suodattimia.

          Hae koko Salesforce-ohjeesta
          Salesforce Document Generation Utilities

          Salesforce Document Generation Utilities

          Salesforce Document Generation Utilities provide tools to help manage and optimize the document generation process. These utilities include the Document Generation Process Cleaner Utility, which permanently deletes old document generation process records and associated data to free up storage space. This utility uses specific Apex classes that can be created and run in the Developer Console to clean up records within a defined timeframe. Additionally, Salesforce offers a feature to run a scheduled job to terminate long-running document generation requests, ensuring system performance by automatically canceling requests that exceed a specified time limit. These utilities help administrators maintain an efficient and performant document generation environment.

          Required Editions

          Available in: Lightning Experience
          Available in: Professional, Enterprise, Unlimited, and Developer Editions
          • Document Generation Process Cleaner Utility
            The Document Generation Process Cleaner Utility permanently deletes records within a specified time frame to create space for content document generation in Salesforce. You can use the utility to delete the document generation process records and their associated token data content documents or only the token data content documents. The utility can clean up 100,000 records and their respective token data files of 1MB size in about 2 hours.
          • Terminate Long-Running Document Generation Requests
            Use the TerminateDocGenRequestCronJob scheduled job to maintain server-side document generation performance by preventing long-running requests from affecting system efficiency.

          Document Generation Process Cleaner Utility

          The Document Generation Process Cleaner Utility permanently deletes records within a specified time frame to create space for content document generation in Salesforce. You can use the utility to delete the document generation process records and their associated token data content documents or only the token data content documents. The utility can clean up 100,000 records and their respective token data files of 1MB size in about 2 hours.

          During server-side document generation, the TokenDataContentDocumentId field in the Document Generation Process entity is used for passing token data that’s more than 131k characters. The TokenDataContentDocumentId field references ContentDocument records that hold the JSON token data as .txt or .json files.

          The utility calls cleanDocumentGenerationProcessAndContentDocument and cleanContentDocument Apex class methods.

          Note
          Note
          • Deleting content documents that are part of an in-progress document generation request can cause the document generation request to fail.

          • It might not be possible to retrieve the deleted data from the recycle bin by the calling Apex class methods cleanDocumentGenerationProcessAndContentDocument and cleanContentDocument.

          1. Apex Classes for Document Generation Process Cleaner Utility
            Use the DocumentGenerationProcessCleanerUtility and BatchDeleteHelper Apex classes to create storage space for content document generation in Salesforce. Create these Apex classes using the sample code we've provided. If required, you can modify the statusList and batchSize fields.
          2. Run the Document Generation Process Cleaner Utility in Developer Console
            Use the Document Generation Process Cleaner Utility to either delete the document generation process records and their associated token data content documents or only the token data content documents.

          Apex Classes for Document Generation Process Cleaner Utility

          Use the DocumentGenerationProcessCleanerUtility and BatchDeleteHelper Apex classes to create storage space for content document generation in Salesforce. Create these Apex classes using the sample code we've provided. If required, you can modify the statusList and batchSize fields.

          The utility calls these Apex class methods:

          • cleanDocumentGenerationProcessAndContentDocument deletes all DocumentGenerationProcess records and their associated token data contentDocument within a specified time frame and status. Only records that use the TokenDataContentDocumentID field are considered.

          • cleanContentDocument deletes all token data contentDocument associated with the DocumentGenerationProcess records within a specified time frame and status. Only records that use the TokenDataContentDocumentID field are considered.

            Note
            Note cleanContentDocument method deletes only the associated contentDocuments. After deletion, the corresponding TokenDataContentDocumentId field value is set to null in DocumentGenerationProcess records.

          The Apex class methods require these parameters.

          ParameterDescription
          Input

          Class-level configurations:

          • statusList: Statuses to consider for deletion. For example, [Completed, Inprogress]

          • batchSize: Batch size for deletion used in BatchDeleteHelper

            You can have up to 2,000 document generation records in a batch. If the batch has more than 2,000 records, the request is split into batches of 2,000 records each.

          Method-level configurations:

          • dstart: Beginning of the time frame to delete document generation records.

          • dend: End of the time frame to delete document generation records.

          Output
          • The batch job jobId
          • Count of successfully deleted records

          DocumentGenerationProcessCleanerUtility Apex Code

          The Document Generation Process Cleaner Utility permanently deletes records within a specified time frame to create space for content document generation in Salesforce.

          Create the following class in your org, and modify it as needed.

          public class DocumentGenerationProcessCleanerUtility {
          
              List<String> statusList = new List<String>{'Success', 'Failure'};               // list of statuses considered for deletion
              Integer batchSize = 2000;                                                       // batch size for deletion used in BatchDeleteHelper, 2000 is max batch size possible
          
              String query = 'select Id, TokenDataContentDocumentId from DocumentGenerationProcess  WHERE LastModifiedDate >= :dstart and LastModifiedDate <= :dend and  TokenDataContentDocumentId != NULL and status IN :statusList';
          
              // Given 'dstart','dend' datetime, delete all documentGenerationProcess records that use TokenDataContentDocument field and have LastModifiedDate = ['dstart','dend'], also delete associated contentDocuments
              public  void cleanDocumentGenerationProcessAndContentDocument(Datetime dstart,Datetime dend) {
                System.Debug('Deleting DocumentGenerationProcess records along with used contentDocuments ...');
                ID batchjobid = Database.executeBatch(new BatchDeleteHelper(false,query,dstart,dend, statusList), batchSize);
                System.debug('Started batch job with ID: ' + batchjobid);
              }
          
              // Given 'dstart','dend' datetime, for all documentGenerationProcess records that use TokenDataContentDocument field and have LastModifiedDate = ['dstart','dend'] delete associated contentDocuments only
              public  void cleanContentDocument(Datetime dstart,Datetime dend) {
                 System.Debug('Deleting only contentDocuments associated with DocumentGenerationProcess records ...');
                ID batchjobid = Database.executeBatch(new BatchDeleteHelper(true,query,dstart,dend,statusList), batchSize);
                System.debug('Started batch job with ID: ' + batchjobid);
              }
          }
          

          Batch Delete Helper Apex Class

          The BatchDeleteHelper is used internally for a batch class.

          Create the following class in your org, and modify it as needed.

          public class BatchDeleteHelper implements Database.Batchable<sObject>, Database.Stateful {
          String query;
          Datetime dstart;
          Datetime dend;
          List<String> statusList;
          Boolean isOnlyContentDocumentDelete;
          
          Integer deletedRecordCount = 0;
          
          
          public BatchDeleteHelper(Boolean isOnlyContentDocumentDeleteArgument,String queryArgument, Datetime dstartArgument, Datetime dendArgument,List<String> statusListArgument){
          query = queryArgument;
          dstart = dstartArgument;
          dend = dendArgument;
          statusList = statusListArgument;
          isOnlyContentDocumentDelete = isOnlyContentDocumentDeleteArgument;
          }
          
          public Database.QueryLocator start(Database.BatchableContext BC){
          System.Debug('Querying data ..');
          return Database.getQueryLocator(query);
          }
          
          
          public void execute(Database.BatchableContext BC, List<DocumentGenerationProcess> scope){
          Database.DeleteResult[] deleteResultList;
          if(isOnlyContentDocumentDelete){
          // need to create ContentDocument Object Set for ContentDocumentOnly deletion
          Set<ContentDocument>contentDocumentSet = new Set<ContentDocument>();
          for(DocumentGenerationProcess documentgenerationprocess:scope){
          String contentDocumentId = documentgenerationprocess.TokenDataContentDocumentId;
          if(contentDocumentId!=null)
          contentDocumentSet.add(new ContentDocument(Id = contentDocumentId));
          }
          deleteResultList = Database.delete(new List<ContentDocument>(contentDocumentSet), false);
          }
          Else{
          deleteResultList = Database.delete(scope, false);
          }
          for(Database.DeleteResult deleteResult : deleteResultList) {
          if (deleteResult.isSuccess()) {
          // System.debug('Successfully deleted record with ID: ' + deleteResult.getId());
          deletedRecordCount++;
          }
          }
          }
          
          public void finish(Database.BatchableContext bc){
          System.Debug('Total ' + deletedRecordCount + ' records deleted successfully');
          }
          }
          

          To run these utility classes, see Run the Document Generation Process Cleaner Utility in Developer Console.

          Run the Document Generation Process Cleaner Utility in Developer Console

          Use the Document Generation Process Cleaner Utility to either delete the document generation process records and their associated token data content documents or only the token data content documents.

          Note
          Note If you haven't created the cleaner utility classes yet, follow the instructions in Apex Classes for Document Generation Process Cleaner Utility.
          1. Click Setup gear icon to open the quick access menu, and then select Developer Console.
          2. From the Debug menu, select Open Execute Anonymous Window.
          3. Copy one of the statements in the Enter Apex Code dialog and specify the start and end times.
            1. To call cleanDocumentGenerationProcessAndContentDocument:
              DocumentGenerationProcessCleanerUtility obj = new DocumentGenerationProcessCleanerUtility();
              DateTime starttime= DateTime.newInstanceGmt(2022,11,08,18,49,48);
              DateTime endtime= DateTime.newInstanceGmt(2022,11,09,01,20,48);
              obj.cleanDocumentGenerationProcessAndContentDocument(starttime,endtime);
              
            2. To call cleanContentDocument use:
              DocumentGenerationProcessCleanerUtility obj = new DocumentGenerationProcessCleanerUtility();
              DateTime starttime= DateTime.newInstanceGmt(2022,11,08,18,49,48);
              DateTime endtime= DateTime.newInstanceGmt(2022,11,09,01,20,48);
              obj.cleanContentDocument(starttime,endtime);
          4. Select the statement you pasted.
          5. Click Execute Highlighted.
            You can view the batch job ID and the count of successfully deleted records in the log files.
          6. Close the Developer Console.

          Terminate Long-Running Document Generation Requests

          Use the TerminateDocGenRequestCronJob scheduled job to maintain server-side document generation performance by preventing long-running requests from affecting system efficiency.

          REQUIRED EDITIONS
          Available in: Lightning Experience
          Available in: Professional, Enterprise, Unlimited, and Developer Editions with Salesforce Document Generation
          USER PERMISSIONS NEEDED
          To run the cron job: CLM Admin

          Prevent document generation requests from running indefinitely by turning on the time-out setting. Specify a time limit for document generation requests. Any individual or batch document generation requests that exceed the specified time limit, but are still in progress, are terminated and marked as failed. The default timeout is set to 6 hours.

          1. From Setup, in the Quick Find box, enter Document Generation, and then select Document Generation Settings.
          2. Click the dropdown next to the Docgen label, and then select Edit.
          3. Turn on the Enable InProgress DocGen Request Time Out setting.
          4. To specify the time interval (in hours) after which the long running document generation requests are terminated, enter a number in InProgress DocGen Request Time Out (hrs).
          5. Click Continue.
            The TerminateDocGenRequestCronJob is added to the Scheduled Jobs list.

          Individual or batch document generation requests that exceed your specified time limit are terminated and marked as failed.

           
          Ladataan
          Salesforce Help | Article