Do After Delete
Last updated 2/04/2026
Overview
The Do After Delete event is a server-side event that executes immediately after a record has been successfully deleted and committed to the database. It allows you to perform actions that depend on the record no longer existing in the database.
The event provides access to the
old
object on the context
parameter, this is the record as it existed before it was deleted.
How it Works
When a record is deleted:
- The Do After Delete event executes on the server after the deletion is committed to the database.
- The oldobject contains the values of the record before it was deleted.
- The record is no longer accessible in the database at this stage.
- Any changes made to the oldobject will not affect the database.
- You can use the oldobject to trigger follow-up logic based on the deleted data.
Use Cases
- Log deletions for audit or compliance purposes
- Remove or clean up related records in other tables
- Trigger notifications when a record is deleted
- Update aggregates or counts affected by the deletion
Example
This function runs after deleting a customer record and logs the deletion in an audit table.
Log record deletion after database removal
// Log record deletion after it has been removed
function doAfterDelete(five, context, result) {
const oldRecord = context.old;
const query = `
INSERT INTO AuditLog (RecordID, FieldName, OldValue, NewValue, ChangedAt)
VALUES (?, ?, ?, ?, ?)
`;
five.executeQuery(
query,
0,
oldRecord.ID,
'Record Deleted',
JSON.stringify(oldRecord),
null,
five.now()
);
return five.success();
}