Call from Apex Class (PDF)

Call OFC's Apex class from the Apex class and save the PDF file. Only PDF file format is supported.

*This feature is available in Office File Creator Pro.

 

How to Call Apex Class

  • From the Apex class, call the "execute" method of the OFC Apex class "ofc2.OFCSavePDF".
  • The parameter is ofc2.OFCSavePDF.Requests class and the return value is ofc2.OFCSavePDF.Results class.
  • Turn on saving of output logs to capture the details of errors.

 

Parameters

Variable Name Setting details
recordId Record Id
template Template Api Name of the OFC_Template Record.
save (file/att *default is file) Set the file output method. The default is "file".

  • file・・・Attached to the record as a file (File).
  • att・・・Attached to the record as a file (Attachment).
execution name Set any execution name, which is stored in the Execution Name of the OFC_Log record.

  • Flow name
  • When subsequent processing is executed after executing an OFC action, it is executed by the trigger flow in the OFC_Log record, etc. The execution name is used for conditional judgment of the trigger flow, etc.

 

Return Values

Variable Name Result Values
isSuccess Returns the success or error of the file output result.

  • True ・・・ Success
  • False ・・・ Error
errorMessage If isSuccess is False, it returns the error content.
filename File name (with extension)
fileNameWithoutExtension File name (without extension)
fileExtension File extension
contentDocumentId If the parameter save is "file", it returns the record Id of the ContentDocument object.
contentDocumentVesionId If the parameter save is "file", it returns the record Id of the ContentVersion object.
attachmentId If the parameter save is "att", it returns the record Id of the ContentVersion object.
log Id Returns the OFC_Log record Id. Returns the result if "Save Logs" is checked on the OFC_Template record.

 

 

Sample Code

ofc2.OFCSavePDF.Requests req = new ofc2.OFCSavePDF.Requests();
req.recordId = 'xxxxxx';
req.templateApiName = 'OpportunityInvoice';
req.executionName = 'Call From Apex';
ofc2.OFCSavePDF.Results result = ofc2.OFCSavePDF.execute(req);
System.debug('result=' + result);

 

 

Apex Batch

Batch Size

The batch size must be set within a range where the total time for OFC processing and other processing is within 60 seconds; for the time to process one file for OFC, check the "Execution Time (sec)" in the OFC_Log record.

 

Approximate Batch Size

(60 seconds - other processing time) / maximum processing time for one file in OFC = batch size

 

e.g., If the maximum processing time for one file in OFC is 5 seconds and the other processing is 8 seconds, the batch size is 10

(60 seconds - 8 seconds) / 5 seconds = 10.4

 

 

Update Merge Fields Before Executing OFC

It is impossible to update records before OFC execution and use the updated values for the merge fields. When updating merge fields before OFC execution, create two batches, one for updating records and one for executing OFC, and call the OFC execution batch in the finish method in the record update batch.

 

 

Note for Apex Batch

  • Batch size should be set to a maximum of 20 or less.
  • OFC's per-file processing time is not constant and may unexpectedly exceed the batch governor limit of seconds. Set a smaller batch size than expected.
  • If the governor limit seconds is exceeded, the error "First error: Apex CPU time limit exceeded" will occur. When a governor limit error occurs, OFC results are not returned because the application cannot catch the error. Also, OFC_Log records are not saved. Please check the batch success/error from Setup > Apex Jobs.

 

 

NoteLimitations

  • Knowledge of Apex development is required. Inquiry support is unavailable for Apex development, such as instructions on how to create Apex.