IOrganizationPartyManagementDELETE Apex Interface

The IOrganizationPartyManagementDELETE interface provides extensibility for DELETE operations through Apex-based validations, mutation-payload adjustments, and post-operation processing. Users can enforce deletion policies, apply soft-delete or metadata logic, and customize final responses without impacting TMF-compliant delete behavior.

This interface supports the following hooks.

The customiseGraphQLQuery is not applicable to DELETE, which is a write operation, so there is no read query to customize. This hook is declared on the read interface (ICommsGET), not on ICommsDELETE. To customize the soft-delete mutation payload, use customiseMutationPayload.

Note

Account Delete Operation Use Cases 

Use CaseHook(s)DescriptionExample ScenariosBenefit
Supply the Soft-Delete Status FieldcustomiseMutationPayloadAdds the status field required to perform a soft delete. The hook can also include deletion metadata or other organization-specific fields in the GraphQL mutation payload.- Set status to Deleted or Inactive
- Add a deletion timestamp
- Record the user who initiated the deletion
- Include custom deletion-reason fields
Required to make the DELETE operation functional while retaining the Account for auditing, recovery, and historical reporting.
Prevent Deletion Under Business RulesapplyCustomValidationsApplies custom business rules before the delete mutation is built. If a rule fails, the operation is stopped with an HTTP 422 response and a clear validation message.- Prevent deletion of an Account with active Contacts
- Block deletion when open Opportunities exist
- Restrict deletion to authorized roles
- Protect Accounts in locked lifecycle states
Blocks invalid or unauthorized deletion attempts early and gives clients a clear, actionable error message.
Resolve an External ID to an Account IDtransformRequestConverts a legacy or external identifier into the canonical Account ID expected by the delete operation and stores it in the shared request context as { id }.- Resolve a legacy customer number to an Account ID
- Map a partner-system key to { id }
- Convert an external billing reference into an Account ID
- Normalize identifiers from migrated systems
Allows clients and legacy integrations to identify Accounts using familiar keys without changing the shared delete contract.
Add Custom Validation FlagsconfigureDefaultValidationsEnables, disables, or adds validation flags for Account deletion according to organization-specific policies. This is especially important when the delete operation does not register built-in validations by default.- Require Account-existence validation
- Enable concurrency or version checks
- Require confirmation for protected Accounts
- Apply stricter deletion checks for regulated organizations
Supports per-organization deletion policies without modifying the shared delete implementation.
Audit or Cascade After DeletionhandlePostOperationRuns after the delete mutation completes and receives the deleteResult summary. It can use the result to perform auditing, cascading updates, event publication, or other side effects.- Write an Account-deletion audit record
- Cascade the deleted status to related records
- Publish an Account-deleted event
- Invalidate related caches or search indexes
- Record deletion metrics
Enables reliable post-delete processing using the deleteResult summary while keeping side effects separate from the core operation.

transformRequest 

This hook transforms the request context before processing any operation. It is invoked early in the request lifecycle, allowing implementers to adjust the context for subsequent extensibility hooks.

Hook Method 

Map<String, Object> transformRequest(Map<String, Object> context)

Sample Apex Implementation 

Resolve an external ID to a Salesforce Contact ID.

1global class OrganizationDeleteTransformRequestExt implements comms_apex_ext.IOrganizationPartyManagementDELETE {
2    global static Map<String, Object> transformRequest(Map<String, Object> context) {
3        if (context == null || !(context.get('id') instanceof String)) {
4            return context;
5        }
6        String idValue = (String) context.get('id');
7        if (idValue.length() != 15 && idValue.length() != 18) {
8            List<Account> matches = [
9                SELECT Id FROM Account WHERE External_Id__c = :idValue LIMIT 1
10            ];
11            if (!matches.isEmpty()) {
12                context.put('id', matches[0].Id);
13            }
14        }
15        return context;
16    }
17    // customiseMutationPayload still REQUIRED — see HOOK 4 ...
18}

configureDefaultValidations 

This hook enables, disables, or modifies the built-in validation rules before they execute.

Hook Method 

Map<String, Boolean> configureDefaultValidations(Map<String, Boolean> defaultValidationConfiguration, Map<String, Object> context)

Sample Apex Implementation 

Add a custom flag consumed by applyCustomValidations.

1global class OrganizationDeleteConfigValidationsExt implements comms_apex_ext.IOrganizationPartyManagementDELETE {
2    global static Map<String, Boolean> configureDefaultValidations(
3        Map<String, Boolean> defaultValidationConfiguration,
4        Map<String, Object> context
5    ) {
6        Map<String, Boolean> overrides = defaultValidationConfiguration != null
7            ? defaultValidationConfiguration.clone()
8            : new Map<String, Boolean>();
9        overrides.put('checkActiveContracts', true);   // your own flag, read in applyCustomValidations
10        return overrides;
11    }
12    // customiseMutationPayload still REQUIRED — see HOOK 4 ...
13}

applyCustomValidations 

This hook validates custom business logic before retrieving customer record. If validation fails, it rejects the request and returns an error response.

The handler processes return values as follows.

Success:

  • Return a map with validationStatus set to “pass” (case-insensitive).
  • The API request continues normally.
  • Other fields in the map are logged but not used.

Failure:

  • Return a map with validationStatus set to “fail” (case-insensitive).
  • The API request is terminated immediately.
  • Raise a ValidationException containing
    • message: value from validationMessage key (or “Validation failed” by default)
    • details: value from validationDetails key (optional)
  • The client receives an HTTP 400 error response.

Hook Method 

Map<String, Object> applyCustomValidations(Map<String, Object> context)

Sample Apex Implementation 

Prevent deletion when the Organization has child Accounts.

1global class OrganizationDeletePreventExt implements comms_apex_ext.IOrganizationPartyManagementDELETE {
2    global static Map<String, Object> applyCustomValidations(Map<String, Object> context) {
3        Map<String, Object> result = new Map<String, Object>();
4        String organizationId = (String) context.get('id');
5        if (organizationId != null) {
6            Integer childAccounts = [
7                SELECT COUNT() FROM Account WHERE ParentId = :organizationId
8            ];
9            if (childAccounts > 0) {
10                result.put('validationStatus', 'fail');
11                result.put('validationMessage',
12                    'Cannot delete this Organization - deletion prevented by custom validation (it still has child Organizations)');
13            }
14        }
15        return result;   // empty => proceed; validationStatus="fail" => HTTP 422
16    }
17    // customiseMutationPayload still REQUIRED — see HOOK 4 ...
18}

customiseMutationPayload 

This hook modifies the mutation payload before deleting a customer record. Use this to add deletion metadata, set soft-delete flags, or apply business logic transformations.

Hook Method 

Map<String, Object> customiseMutationPayload(Map<String, Object> request, Map<String, Object> context)

Sample Apex Implementation 

Supply the soft-delete status field.

1global class OrganizationDeleteCustomMutationExt implements comms_apex_ext.IOrganizationPartyManagementDELETE {
2    global static Map<String, Object> customiseMutationPayload(
3        Map<String, Object> graphQLAsMap,
4        Map<String, Object> context
5    ) {
6        Map<String, Object> node = new Map<String, Object>{
7            'path'      => 'softDeleteOrganization',
8            'addFields' => new Map<String, Object>{
9                'Status__c'          => 'Inactive',
10                'Deletion_Reason__c' => 'Deleted via TMF632 Organization API'
11            }
12        };
13        return new Map<String, Object>{
14            'nodes' => new List<Object>{ node }
15        };
16    }
17    // ... other hooks return null / empty map ...
18}

handlePostOperation 

This hook post-processes and transforms the API response after data retrieval.

Hook Method 

Map<String, Object> handlePostOperation(Map<String, Object> graphQLQueryResultAsMap, Map<String, Object> constructedTMFResponse, Map<String, Object> context)

Sample Apex Implementation 

Audit the deletion.

1global class OrganizationDeleteHandlePostOpExt implements comms_apex_ext.IOrganizationPartyManagementDELETE {
2    global static Map<String, Object> handlePostOperation(
3        Map<String, Object> graphQLQueryResultAsMap,
4        Map<String, Object> constructedTMFResponse,
5        Map<String, Object> context
6    ) {
7        Object dr = context != null ? context.get('deleteResult') : null;
8        if (dr instanceof Map<String, Object>) {
9            Map<String, Object> deleteResult = (Map<String, Object>) dr;
10            if (Boolean.TRUE.equals(deleteResult.get('success'))) {
11                insert new Organization_Deletion_Log__c(
12                    Organization_Id__c = (String) deleteResult.get('deletedId'),
13                    Deleted_By__c      = UserInfo.getUserId()
14                );
15            }
16        }
17        return null;   // no body for HTTP 204
18    }
19    // customiseMutationPayload still REQUIRED — see HOOK 4 ...
20}

Full Implementation Example 

Here’s a complete sample Apex implementation using all supported hooks.

1/**
2 * Complete TMF632 Organization (Party Management) DELETE API extension,
3 * demonstrating all hooks. customiseMutationPayload supplies the required soft-delete field.
4 */
5global class OrganizationPartyManagementDELETEExtension implements comms_apex_ext.IOrganizationPartyManagementDELETE {
6
7
8    // Hook 1: normalize / resolve the id.
9    global static Map<String, Object> transformRequest(Map<String, Object> context) {
10        return context;
11    }
12
13
14    // Hook 2: DELETE has no default validators; keep it that way.
15    global static Map<String, Boolean> configureDefaultValidations(
16        Map<String, Boolean> defaultValidationConfiguration,
17        Map<String, Object> context
18    ) {
19        return new Map<String, Boolean>();
20    }
21
22
23    // Hook 3: block deletion when there are child Organizations.
24    global static Map<String, Object> applyCustomValidations(Map<String, Object> context) {
25        Map<String, Object> result = new Map<String, Object>();
26        String organizationId = (String) context.get('id');
27        if (organizationId != null) {
28            Integer childAccounts = [
29                SELECT COUNT() FROM Account WHERE ParentId = :organizationId
30            ];
31            if (childAccounts > 0) {
32                result.put('validationStatus', 'fail');
33                result.put('validationMessage',
34                    'Cannot delete this Organization - deletion prevented by custom validation (it still has child Organizations)');
35            }
36        }
37        return result;
38    }
39
40
41    // Hook 4 (REQUIRED): supply the soft-delete status field on the softDeleteOrganization node.
42    global static Map<String, Object> customiseMutationPayload(
43        Map<String, Object> graphQLAsMap,
44        Map<String, Object> context
45    ) {
46        Map<String, Object> node = new Map<String, Object>{
47            'path'      => 'softDeleteOrganization',
48            'addFields' => new Map<String, Object>{ 'Status__c' => 'Inactive' }
49        };
50        return new Map<String, Object>{ 'nodes' => new List<Object>{ node } };
51    }
52
53
54    // Hook 5: audit the deletion (no response body).
55    global static Map<String, Object> handlePostOperation(
56        Map<String, Object> graphQLQueryResultAsMap,
57        Map<String, Object> constructedTMFResponse,
58        Map<String, Object> context
59    ) {
60        Object dr = context != null ? context.get('deleteResult') : null;
61        if (dr instanceof Map<String, Object>
62            && Boolean.TRUE.equals(((Map<String, Object>) dr).get('success'))) {
63            // audit / downstream cleanup (e.g. re-parent child Accounts, remove AAR records)
64        }
65        return null;
66    }
67}