---
schema_version: "1"
id: 4ec8a246a4cb88dce1ef946e72481a0af50ffbfec582e9837905c02a05b5f403
title: Metering and Throttling for Document Generation
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/ind/264-0-0/doc_gen_metering_and_throttling.md
canonical_url: https://help.salesforce.com/s/articleView?id=ind.doc_gen_metering_and_throttling.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f6040edfc84ef75cc872044ebf00cd2080bbaeb3d13df0d44a30ba4bffcb1a52
description: Learn how to optimize the performance of your document generation solution with metering and throttling. Metering measures resource utilization levels and throttling controls resource access and use based on defined rules.
products:
  - Omnistudio Doc Gen
release: "264"
---
# Metering and Throttling for Document Generation

Learn how to optimize the performance of your document generation solution with metering and throttling. Metering measures resource utilization levels and throttling controls resource access and use based on defined rules.

## Metering

Metering measures the number of server-side documents that you generate hourly and daily. The default hourly and daily limits for processing server-side document generation requests can be found in [Document Generation Limitations](https://help.salesforce.com/s/articleView?id=ind.doc_gen_limitations_with_document_generation_two.htm&language=en_US).

## Throttling

Throttling maintains consistency and resilience of the server-side document generation service by managing incoming server-side document generation requests from multiple orgs. Throttling can also prevent service degradation caused by high volume of requests at peak hours by blocking requests that exceed the default limits. The request details are saved in the Document Generation Processes entity. You can retrieve the blocked requests and retry the server-side document generation.

## View Document Generation Requests

You can view the document generation requests and their status from the Document Generation Processes page.

Use this sample URL to view the Document Generation requests: `https://{{baseUrl}}/lightning/o/DocumentGenerationProcess/home`. Replace the base url with your org details.

Here's an example of the Document Generation Processes page. In this example, there are blocked document generation requests because the daily limit has been reached.

![List of Document Generation Requests and its Status](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-document_generation-264-0-0-production-enus/f76d5573-56ce-4576-b4b2-7a4f1f2e622b/resources-product/images/doc_gen/doc_gen_document_generation_processes.png)

## Retrieve Blocked Server-Side Document Generation Requests Using Apex Class

Retrieve blocked server-side document generation requests for specific timeframes. Blocked requests are reprocessed via new server-side document generation requests.

## Sample Code to Retrieve Blocked Requests

Modify the sample code to create an Apex class for retrieving blocked server-side document generation requests.

The required input parameters for the code include:

 
| Parameter | Description |
| --- | --- |
| startTime | Start time of the timeframe to retrieve blocked requests. |
| endTime | End time of the timeframe to retrieve blocked requests. |

**Sample Code**

```java
Global class DocGenRetryBlockedBatch implements Database.Batchable<sObject> {
	private DateTime startTime;
	private DateTime endTime;
	public DocGenRetryBlockedBatch(DateTime startTime, DateTime endTime) {
    	this.startTime = startTime;
 	   this.endTime = endTime;
	}
   
	global Database.QueryLocator start(Database.BatchableContext BC) {
    	DateTime dt = System.Now().addHours(-1);
    	String query = 'SELECT Id, Type ,RequestText, TokenDataContentDocumentId , TokenData from DocumentGenerationProcess where Status =\'Blocked\' and LastModifiedDate >=:startTime and LastModifiedDate <=:endTime';
    	return Database.getQueryLocator(query);
	}


	global void execute(Database.BatchableContext BC, List<DocumentGenerationProcess> blockedList) {
    	List<DocumentGenerationProcess> ls = new List<DocumentGenerationProcess>();
    	for(DocumentGenerationProcess blockedObject:blockedList)
    	{
        	DocumentGenerationProcess myCustomObject = new DocumentGenerationProcess (
            	Type = blockedObject.Type, Status = 'InProgress',
            	RequestText= blockedObject.RequestText,
            	TokenDataContentDocumentId= blockedObject.TokenDataContentDocumentId,
            	TokenData = blockedObject.TokenData
        	);
        	ls.add(myCustomObject);  
    	}
    	insert ls;
	}
   
	global void finish(Database.BatchableContext BC) {
    	// execute any post-processing operations
     }
}
```

## Create DocGenRetryBlockedBatch Apex Class

After creating the code for retrieving blocked requests, create an Apex class in the Developer Console.

1. Click the quick access menu ![Setup gear icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-document_generation-264-0-0-production-enus/f76d5573-56ce-4576-b4b2-7a4f1f2e622b/resources-product/images/doc_gen/doc_gen_setting_icon.png) and select Developer Console.
2. Select **File** | **New****Apex Class**.
3. For Name, enter the name as DocGenRetryBlockedBatch, and then click **OK**.
4. Enter the code that you created for retrieving blocked requests into the dialog.
    
    For more information, see [Sample Code to Retrieve Blocked Requests](https://help.salesforce.com/s/articleView?id=ind.doc_gen_metering_and_throttling.htm&release=264.0.0&type=5 "Modify the sample code to create an Apex class for retrieving blocked server-side document generation requests.").
5. Save your changes.

## Retrieve and Reprocess Blocked Requests

After creating an Apex class, run the code for retrieving blocked requests in the Developer Console. Ensure that the start time and end time are defined in the Sample Code to Retrieve Blocked Requests.

1. Click the quick access menu ![Setup gear icon](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-ind-document_generation-264-0-0-production-enus/f76d5573-56ce-4576-b4b2-7a4f1f2e622b/resources-product/images/doc_gen/doc_gen_setting_icon.png) and select **Developer Console**.
2. From the Debug menu, select **Open Execute Anonymous Window**.
3. In the Enter Apex Code dialog, enter this sample statement:
    
    ```java
    DocGenRetryBlockedBatch dgrb = new DocGenRetryBlockedBatch(
    DateTime.newInstance(2022,10,17), DateTime.now());
    Database.executeBatch(dgrb);
    ```
4. Select the statement you pasted.
5. Click **Execute Highlighted**.
6. Close the Developer Console.