- 04 Oct 2023
- 2 Minutes to read
- Print
- DarkLight
CsvImportPostProcessorData
- Updated on 04 Oct 2023
- 2 Minutes to read
- Print
- DarkLight
Use this Apex hook to configure the post-processing logic for lines imported into Salesforce through the CSV Import component.
The Apex hook class must implement the zpf.CsvImportCustomWorkflowPostProcessor interface.
You must specify its name in the Workflow Custom Post Processor Class field of the CSV Import configuration in the App Builder.
Learn how to configure post-processing of imported lines.
Interface definition
global interface CsvImportCustomWorkflowPostProcessor
{
void execute(zpf.CsvImportPostProcessorData data, Map<String, String> params);
}
params—Mapping of parameters specified in the Workflow Custom Post Processor Parameters field of the CSV Import component configuration in the App Builder.
Apex class definition
global with sharing class CsvImportPostProcessorData
{
global String externalBulkDataJobId;
global zpf__CSVImportHistory__c csvImportHistory;
}
- externalBulkDataJobId—ID of the current bulk data job for which records were uploaded to Salesforce. It can be used to query only uploaded records.
- csvImportHistory—History record for the current CSV import. This record has only Id and zpf__Status__c fields queried. To use other fields, you need to query them specifically.
Example: class implementation
global with sharing class SampleCsvImportCustomWorkflowPostProcessor implements zpf.CsvImportCustomWorkflowPostProcessor
{
global void execute(zpf.CsvImportPostProcessorData data, Map<String, String> params)
{
if (data.csvImportHistory.zpf__Status__c == 'Failed')
{
finish(data.csvImportHistory);
return; // Skip post-processing if Job Workflow failed
}
// Query records, filtered by data.externalBulkDataJobId
// Use parameters from params map
// Execute any post-processing
// If you see there are not enough resources in scope of this transaction to execute post-processing,
// you can postpone it for now and the user will be able to manually retry it in a new transaction.
// To postpone, throw this exception:
// throw new zpf.CsvImportCancelPostProcessingException();
finish(data.csvImportHistory);
}
private static void finish(zpf__CSVImportHistory__c csvImportHistory)
{
zpf.DatabaseUtil.updateObjects(csvImportHistory); // Unlock UI
new zpf.CsvImportFinishedNotificationSender(new Set<String>{csvImportHistory.Id}).notify(); // Send notification to User via SF Notifications
}
}
General considerations
The post-processor is executed regardless of the job workflow status.
The zpf__Status__c field of the csvImportHistory record shows the import job status. At the end of your logic, you should update this record in the Salesforce database to unlock the CSV Import UI.
Add the optional zpf__PostProcessorError__c field to specify an error message to display to users. The message appears even if post-processing succeeds.
Add the zpf.CsvImportCancelPostProcessingException to postpone post-processing if there are not enough resources in scope of that transaction. In this case, a user who initiated the import will see Retry and Cancel buttons.
The record is locked for all users until the Retry or Cancel action is executed successfully.
To delete uploaded records as part of the Cancel operation, add the following parameters in the Workflow Custom Post Processor Parameters field of the CSV Import component configuration:
- sObjectName
- externalBulkDataJobIdFieldName
If you add an exception to the post-processing logic, an exception message will be written in the zpf__PostProcessorError__c field of the csvImportHistory record and displayed to users. The csvImportHistory record will be automatically persisted and the UI will be unlocked. In this case, the zpf__Status__c of the csvImportHistory record will be the same as the status of the Job Workflow.
An administrator can unlock a record that was locked because of a retry or cancel operation. To do this:
- Query the zpf__CSVImportHistory__c record with the In Progress status, ID of the user in the CreatedById field, and not empty zpf__PostProcessorRetryData__c field.
- Change the status of the history record to Completed or Failed to unlock the UI.
If you leave the zpf__PostProcessorRetryData__c field populated and later switch the status to In Progress, the record will be locked again. The user who initiated the import will be able to complete it by using Retry or Cancel actions.