You are here:
Delete Health Verification Attachments and Health Card Records Automatically with an Apex Job
Help keep customers’ personal health information private and safe by regularly deleting verification files and Health Card records. Simply schedule the job, and it runs at the specified time.
The job uses the schedulable class SafetyCloudPurger to automatically delete the verification file attached to a
Health Verification record or to delete Health Card records and associated data, such as
dose information.
Each batch performs these actions on Health Verification records that have a Health Verification Status of Verified.
- Fetch Health Verification records with
EventDate__c <= YESTERDAY AND AttachmentPurgedTimestamp__c = null. - Delete the Health Card record and associated data.
- If the record has
attachment:- Delete the attachment record.
- Set
AttachmentPurgedTimestamp__cto the current time.
Safety Cloud relies on a Custom Setting named Safety Cloud Purge Setting to determine how many days after an event to wait before purging file attachments and Health Card-related data from the system.
By default, Safety Cloud purges Health Card and Health Verification data 1 day after the event. To modify the Safety Cloud Purge setting complete these steps.
- From Setup, in the Quick Find box, enter Custom Settings, and then select Custom Settings.
- Select the Safety Cloud Purge Setting.
- Click Manage.
If there’s no Default Organization Level Value, Safety Cloud purges Health Verification and Health Card-related data 1 day after the event.
- To set a default value for purging data, click New, and set a value for Days After Event.
- Save your changes.
After setting the Default Organization Level Value, you can go back at any time and edit the value specified in Days After Event.
To schedule the job, complete these steps.
- From Setup, in the Quick Find box, enter Apex Classes, and then select Apex Classes.
- Click Schedule Apex.
- Enter the job name. We recommend Health Verification Data Purge.
- In the search bar, enter SafetyCloudPurger, and select it.
- Specify the start and end dates for the Apex scheduled class. If you specify a single day, the job runs only one time.
- Specify a preferred start time. The exact start time depends on service availability.
- Save your changes.
When it completes, you can see the job’s information on the Apex Jobs page, such as whether it passed or failed, how long it took to process, and the number of records processed.

