Search.../

onContactDeleted( )

An event that triggers when a contact is deleted.

Description

The onContactDeleted() event handler runs when a contact is deleted. The received ContactDeletedEvent object contains event metadata.

If a contact is deleted as part of a merge, metadata.originatedFrom is sent as "merge". Otherwise, originatedFrom is omitted.

Note: Backend events don't work when previewing your site.

Syntax

function onContactDeleted(event: ContactDeletedEvent): void

onContactDeleted Parameters

NAME
TYPE
DESCRIPTION
event
ContactDeletedEvent

Metadata for the event.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

An event fired when a contact is deleted

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixCrm_onContactDeleted(event) {
6 const contactId = event.metadata.entityId;
7 console.log('Contact deleted', event);
8}
9
10/* Full event object:
11 * {
12 * "metadata": {
13 * "id": "225bb629-4813-4c58-91ec-07aa5fbf069c",
14 * "entityId": "ab1b7f0f-fd39-45ac-b13b-cb02c93b5e50",
15 * "eventTime": "2021-02-10T19:18:03.442207Z",
16 * "triggeredByAnonymizeRequest": false
17 * }
18 * }
19 */
Ignore a delete event if it originated from a merge

Copy Code
1// Place this code in the events.js file
2// of your site's Backend section.
3// Add the file if it doesn't exist.
4
5export function wixCrm_onContactDeleted(event) {
6
7 if (event.metadata.originatedFrom === 'merge') {
8
9 console.log('Contact was a source contact for a merge. Ignoring event.');
10 return;
11
12 } else {
13
14 const deletedContactId = event.metadata.entityId;
15 console.log('Contact deleted', event);
16
17 // Handle the event
18
19 }
20
21}
22
23/* Full event object:
24 * {
25 * "metadata": {
26 * "entityId": "c8e08afd-deac-40f7-b4c1-b42409d35df7",
27 * "id": "1c7adeb5-c54a-4af0-8ea9-315d95cb5899",
28 * "eventTime": "2022-02-02T22:05:47.361876Z",
29 * "originatedFrom": "merge",
30 * "triggeredByAnonymizeRequest": false
31 * }
32 * }
33 */