You are here:
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.
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.
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
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.
-
Click the quick access menu
and select Developer Console.
- Select .
- For Name, enter the name as DocGenRetryBlockedBatch, and then click OK.
-
Enter the code that you created for retrieving blocked requests into the
dialog.
For more information, see Sample Code to Retrieve Blocked Requests.
- 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.
-
Click the quick access menu
and select Developer Console.
- From the Debug menu, select Open Execute Anonymous Window.
-
In the Enter Apex Code dialog, enter this sample statement:
DocGenRetryBlockedBatch dgrb = new DocGenRetryBlockedBatch( DateTime.newInstance(2022,10,17), DateTime.now()); Database.executeBatch(dgrb); - Select the statement you pasted.
- Click Execute Highlighted.
- Close the Developer Console.

