Apex Actions to be used in Flows:
Class Name: IdealDocAsyncAction
Action Label: Create an IdealDoc based on a job definition
Action Category: IdealDoc
Action Param: IdealDocJobDefDataType
1 Calls the IdealDocController.createIdealDocPostRequestcreateIdealDocPostRequest
method to send the IdealDoc post request
2 Calls the IdealDocController.createIdealDocGetStatusJob method which polls for the result and attaches the resulting file to the targetRecordId if completed
LWC enabled Apex Methods
IdealDocController.sendIdealDocRequest(IdealDocJobDefDataType jobDefinition)
Sends an IdealDoc POST request to the IdealDoc Server using the setting name defined in the jobDefinition.settingsConfigName attribute.
1 Executes the param query (if defined)
2 Executes the data queries
3 creates the POST request with the data query results and the mapping definition
Returns a json string containing the request result with the attributes: id, name, status, result, format, archive, subscription, metaData
IdealDocController.createIdealDocGetStatusJob(String requestInfo, IdealDocJobDefDataType jobDefinition)
requestInfo is a JSON String parameter containing the following JSON attributes:
id: the jobId to be fetched
status: the status of the job
format: the format of the resulting document
name: the file name
Tries for max 12 times to sends a GET status request using the messageId from the initial POST request with a wait time of max 5 seconds (i.e. the IdealDoc server waits max 5 seconds before returning the status).
Since its not possible to wait in Apex unless using a scheduled async job, making the IdealDoc server wait is a nice option (10 Seconds is the Apex Callout Timeout, so 5 Secs seems to be a good value)
If, after 12 tries with 5 seconds wait (= 60 Seconds), the job is still not completed, an async Apex Job called IdealDocGetStatusJob will be created which after a delay of one minute again checks the status of the job. If the job is still not completed it creates a new job to run after another minute. It does so for max. 9 times which gives roughly 9 minutes waiting. So, in total we wait for max. 10 minutes for a job to complete. Otherwise the job will not be fetched and an error message will be written in the Salesforce log.
If the job is completed, the resulting file will be attached to the Salesforce record with id jobDefinition.targetRecordId
IdealDocController.sendIdealDocPostRequest(String settingName, String requestBody)
Sends the requestBody (JSON String) as POST request to the IdealDoc server using the given settingName
IdealDocController.sendIdealDocGetRequest(String settingName, String requestId)
Sends a GET request to the IdealDoc server using the settingName to get the status of the job with the request id (requestId).
The method return a JSON string in the following format:
{id: jobIdstatus: status of the job (completed, pending, checking)format: the file format (docx, pdf)result: the base64 encoded result file (if the job is completed)name: the file name (without the suffix)archive: whether the resulting file is returned as archive (zip)}