The IIndividualPartyManagementPOST Apex interface provides extensibility for POST operations through Apex pre- and post-hooks and GraphQL query customization. Implementations can validate incoming requests, modify query structures, and refine the response to support business-specific retrieval rules while maintaining TMF-compliant behavior.
This table lists common use cases and the hooks required for the POST operation.
Use Case
Hook(s)
Description
Example Scenarios
Benefit
Default or Normalize Request Fields
transformRequest
Transforms the incoming request before validation or mutation processing. It can supply default values, normalize formats, and map client-specific fields to the canonical request structure.
- Apply a default contact status - Normalize phone numbers or email addresses - Standardize country and region codes - Map legacy fields to TMF632 fields
Ensures consistent, standardized data at the point of creation.
Relax or Tighten Built-In Validators
configureDefaultValidations
Enables, disables, or adjusts built-in validation flags for create requests according to organization-specific requirements.
- Require stricter email or phone validation - Disable a validator that is not applicable to an internal channel - Require additional identity checks in regulated organizations - Apply different validation policies by tenant or environment
Supports per-organization validation policies without modifying the shared create implementation.
Enforce Custom Business Rules
applyCustomValidations
Evaluates organization-specific business and eligibility rules before the create mutation is built. Invalid payloads are rejected early with an HTTP 400 response and a clear validation message.
- Prevent duplicate contacts based on organization rules - Require consent before creating a marketing contact - Validate permitted customer types or lifecycle states - Require additional fields for specific regions
Rejects invalid payloads early and prevents inconsistent or noncompliant records from being created.
Set Organization-Specific Contact Fields
customiseMutationPayload
Adds or modifies organization-specific Contact fields in the GraphQL mutation payload before execution. This supports fields that extend beyond the standard TMF632 schema.
- Set an internal customer segment - Add a source-system identifier - Populate custom consent or preference fields - Store organization-specific classification data
Persists custom Contact fields beyond the TMF632 data model while preserving the shared API contract.
Audit or Integrate After Creation
handlePostOperation
Runs after the create mutation completes and performs post-operation side effects using the creation result. It can write audit records, publish events, or invoke downstream integrations.
- Write a contact-creation audit record - Publish a customer-created event - Synchronize the contact with a downstream CRM or marketing platform - Trigger onboarding or notification workflows
Enables reliable auditing and downstream processing after successful creation 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.
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)
1global class IndividualPostValidationExt implements comms_apex_ext.IIndividualPartyManagementPOST {2 global static Map<String, Object> applyCustomValidations(Map<String, Object> context) {3 Map<String, Object> result = new Map<String, Object>();4 if (!(context.get('requestBody') instanceof Map<String, Object>)) {5 return result;6 }7 Map<String, Object> body = (Map<String, Object>) context.get('requestBody');8910 if (body.get('contactMedium') instanceof List<Object>) {11 for (Object cmObj : (List<Object>) body.get('contactMedium')) {12 Map<String, Object> cm = (Map<String, Object>) cmObj;13 if ('EmailContactMedium'.equals(cm.get('@type'))) {14 String email = (String) cm.get('emailAddress');15 if (email != null && !email.endsWithIgnoreCase('@acme.com')) {16 result.put('validationStatus', 'fail');17 result.put('validationMessage',18 'Email domain not allowed. Individuals must use an @acme.com address.');19 }20 }21 }22 }23 return result; // empty => proceed; validationStatus="fail" => HTTP 40024 }25 // ... other hooks return null / empty map ...26}
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.
1global class IndividualPostHandlePostOpExt implements comms_apex_ext.IIndividualPartyManagementPOST {2 global static Map<String, Object> handlePostOperation(3 Map<String, Object> graphQLQueryResultAsMap,4 Map<String, Object> constructedTMFResponse,5 Map<String, Object> context6 ) {7 String newId = constructedTMFResponse != null8 ? (String) constructedTMFResponse.get('id')9 : null;10 if (newId != null) {11 EventBus.publish(new Individual_Created__e(Individual_Id__c = newId));12 }13 return null; // ignored for POST14 }15 // ... other hooks return null / empty map ...16}
Full Implementation Example
Here’s a complete sample Apex implementation using all supported hooks.
1/**2 * Complete TMF632 Individual (Party Management) POST API extension,3 * demonstrating all hooks with business logic.4 */5global class IndividualPartyManagementPOSTExtension implements comms_apex_ext.IIndividualPartyManagementPOST {678 // Hook 1: normalize the request body.9 global static Map<String, Object> transformRequest(Map<String, Object> context) {10 if (context != null && context.get('requestBody') instanceof Map<String, Object>) {11 Map<String, Object> body = (Map<String, Object>) context.get('requestBody');12 if (body.get('title') == null) {13 body.put('title', 'Contact');14 }15 }16 return context;17 }181920 // Hook 2: keep the default validations (all three enabled).21 global static Map<String, Boolean> configureDefaultValidations(22 Map<String, Boolean> defaultValidationConfiguration,23 Map<String, Object> context24 ) {25 return new Map<String, Boolean>();26 }272829 // Hook 3: enforce a corporate email domain.30 global static Map<String, Object> applyCustomValidations(Map<String, Object> context) {31 Map<String, Object> result = new Map<String, Object>();32 if (context.get('requestBody') instanceof Map<String, Object>) {33 Map<String, Object> body = (Map<String, Object>) context.get('requestBody');34 if (body.get('contactMedium') instanceof List<Object>) {35 for (Object cmObj : (List<Object>) body.get('contactMedium')) {36 Map<String, Object> cm = (Map<String, Object>) cmObj;37 if ('EmailContactMedium'.equals(cm.get('@type'))) {38 String email = (String) cm.get('emailAddress');39 if (email != null && !email.endsWithIgnoreCase('@acme.com')) {40 result.put('validationStatus', 'fail');41 result.put('validationMessage',42 'Email domain not allowed. Individuals must use an @acme.com address.');43 }44 }45 }46 }47 }48 return result;49 }505152 // Hook 4: add custom Contact fields to the create mutation.53 global static Map<String, Object> customiseMutationPayload(54 Map<String, Object> graphQLAsMap,55 Map<String, Object> context56 ) {57 Map<String, Object> node = new Map<String, Object>{58 'path' => 'individualData',59 'addFields' => new Map<String, Object>{ 'LeadSource' => 'Web', 'Department' => 'Sales' }60 };61 return new Map<String, Object>{ 'nodes' => new List<Object>{ node } };62 }636465 // Hook 5: side effect only (return ignored).66 global static Map<String, Object> handlePostOperation(67 Map<String, Object> graphQLQueryResultAsMap,68 Map<String, Object> constructedTMFResponse,69 Map<String, Object> context70 ) {71 return null;72 }73}
Response Structure
Request Body
A TMF632 Individual create payload supports the following input fields:
Scalars:@type (must be "Individual"), givenName, familyName, title, and birthDate.
contactMedium[]: Each item includes an @type discriminator and a corresponding value field:
EmailContactMedium → emailAddress
PhoneContactMedium → phoneNumber
FaxContactMedium → faxNumber
GeographicAddressContactMedium → street1, city, stateOrProvince, postCode, country
relatedParty[]: Each item includes a role and a partyOrPartyRole with @type = "PartyRef", @referredType = "Organization", and id set to the Account ID.
The first entry sets Contact.AccountId.
Additional entries create AccountContactRelation records and require Contacts to Multiple Accounts to be enabled.