Batch SDK Doc Generation Using Batch Apex
1
2
3
4
5
5. Execute the S-Docs SDK Batch Generation
String generatedDocumentAsString = SDOC.DocumentSDK.generateDocsInBatch(
oppIDs,
templateIDs,
1
// REMOVE COMMENTS FROM THIS SECTION TO ENABLE BATCHACTIONS
//,
//new List<SDOC.BatchAction> {
// new SDOC.CombinedDocumentHandler()
//}
);
return generatedDocumentAsString;public class CallableBatchSolution implements System.Callable {
/**
* The standard call method for the Callable interface
* @param action The name of the action to perform
* @param args A map of arguments passed to the action
* @return An Object (in this case, the result String from S-Docs)
*/
public Object call(String action, Map<String, Object> args) {
switch on action {
when 'generateBatchDocuments' {
return this.generateBatchDocuments();
}
when else {
throw new ExtensionMalformedException('Method not implemented');
}
}
}
public String generateBatchDocuments() {
// 1. Query the Opportunities based on your criteria
List<Opportunity> opportunities = [
SELECT Id
FROM Opportunity
LIMIT 5
];
// 2. Extract the Opportunity IDS
List<Id> oppIDs = new List<Id>();
for (Opportunity opp : opportunities) {
oppIDs.add(opp.Id);
}
// 3. Set up the S-Docs Template IDs
List<SDOC__SDTemplate__c> templates = [
SELECT Id
FROM SDOC__SDTemplate__c
WHERE SDOC__Base_Object__c = 'Opportunity' AND SDOC__E_Sign_Vendor__c = NULL AND SDOC__Template_Format__c = 'PDF'
LIMIT 2 Offset 20
];
// 4. Extract the Template IDs
Set<Id> templateIDs = new Set<Id>();
for (SDOC__SDTemplate__c sdtemp : templates) {
templateIDs.add(sdtemp.Id);
}
// 5. Execute the S-Docs SDK Batch Generation
// Method Takes in 5 total Params, signature in the form generateDocsInBatch(baseRecords, templateIds, n)
// baseRecordIds (Type: Id): The list of the records used for generating documents.
// templateIds (Type: Id): The set of IDs of templates to generate.
// batchSize (Type: Integer): The size of each batch in a job. (Default value is 5)
// batchActions (Type: List): List of batch actions to perform on the generated documents.
// CombinedDocumentHandler The CombinedDocumentHandler is built-in functionality that combines all generated documents into one PDF.
String generatedDocumentAsString = SDOC.DocumentSDK.generateDocsInBatch(
oppIDs,
templateIDs,
1
// REMOVE COMMENTS FROM THIS SECTION TO ENABLE BATCHACTIONS
//,
//new List<SDOC.BatchAction> {
// new SDOC.CombinedDocumentHandler()
//}
);
return generatedDocumentAsString;
}
public class ExtensionMalformedException extends Exception {}
}Handling Errors:
PreviousSDK How-to Guide: Batching and Combining DocumentsNextSDK Batch: Too Many Queueable Jobs Added to Queue
Last updated
Was this helpful?

