The ICustomerManagementPOST interface enables customization of POST operations using Apex lifecycle hooks. Implementations can validate and enrich creation payloads, apply additional business logic, and modify the final response structure, ensuring that customer-creation workflows remain flexible maintaining TMF-compliant behavior.
This interface supports the following hooks.
note: These hooks are not used for the Customer Management API. If implemented, the method may be invoked, but its return values are ignored.
configureDefaultValidationscustomiseGraphQLQuery
Creation Lifecycle Use Cases and Hook Mapping
The following table lists common use cases for POST operation.
| Use Case | Hook(s) | Description <div style="width:290px"></div> | Example Scenarios <div style="width:290px"></div> | Benefit <div style="width:290px"></div> |
|---|---|---|---|---|
| Enforce Business Rules | applyCustomValidations |
Validates customer creation requests before processing to ensure they comply with business rules, data quality constraints, and organizational policies. Prevents invalid or duplicate customer records from entering the system. | • Block creation of customers with duplicate names or identifiers• Reject requests with invalid customer types or lifecycle statuses• Enforce mandatory business validations (e.g., email/phone standards) | Prevents invalid or low-quality customer records from being created, improving data integrity |
| Auto-Populate Fields | customiseMutationPayload |
Automatically enriches or computes field values during customer creation. Ensures consistent and accurate population of derived or dependent fields before data is persisted. | • Generate customer display name from first/last name• Auto-calculate classification, segment, or service level• Populate geo-encoding or internal routing codes | Reduces manual data entry, enforces consistency, and improves data accuracy |
| Audit Trail | handlePostOperation |
Adds audit metadata to newly created customer records after persistence, ensuring every creation event is traceable for security and compliance. | • Stamp “createdBy”, “createdAt” values• Add system identifiers for correlation or traceability• Trigger downstream audit logging services | Maintains a reliable and compliant audit trail across all customer creation events |
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
public Map<String, Object> transformRequest(Map<String, Object> context) {
if (context == null) {
return context;
}
Object idObj = context.get('id');
if (idObj == null || !(idObj instanceof String)) {
return context;
}
String idValue = (String)idObj;
// Check if the ID looks like a Salesforce ID (starts with 001, 003, etc.)
// If not, assume it's an AccountNumber and resolve it
if (idValue.length() == 15 || idValue.length() == 18) {
// Looks like a Salesforce ID, return context as-is
return context;
}
// Query Account objects where AccountNumber matches the provided ID
List<Account> accounts = [
SELECT Id, AccountNumber
FROM Account
WHERE AccountNumber = :idValue
LIMIT 1
];
// If found, replace the ID in context with the Salesforce ID
if (!accounts.isEmpty() && accounts[0].AccountNumber != null) {
context.put('id', accounts[0].Id);
}
return context;
}
applyCustomValidations
This hook validates custom business logic before creating a customer record. If validation fails, rejects the request and returns an error response.
The handler processes return values as follows.
Success:
- Return a map with validationStatus set to any value other than "fail" (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
public Map<String, Object> applyCustomValidations(Map<String, Object> context) {
// Input context:
// {
// api: 'CustomerManagement',
// version: '4.0',
// requestBody: { name: 'Acme Corp', type: 'Customer', status: 'Active' }
// }
Map<String, Object> requestBody = (Map<String, Object>) context.get('requestBody');
Map<String, Object> validationResult = new Map<String, Object>();
try {
String customerName = (String) requestBody.get('name');
String customerType = (String) requestBody.get('type');
String status = (String) requestBody.get('status');
// Validate required fields
if (String.isBlank(customerName)) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Customer name is required');
return validationResult;
}
// Validate customer type
if (!isValidCustomerType(customerType)) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Invalid customer type: ' + customerType);
validationResult.put('validationDetails', new Map<String, Object>{
'allowedTypes' => new List<String>{'Customer', 'Prospect', 'Partner'}
});
return validationResult;
}
// Check for duplicate customer names
List<Account> existingAccounts = [SELECT Id FROM Account WHERE Name = :customerName LIMIT 1];
if (!existingAccounts.isEmpty()) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Customer with name "' + customerName + '" already exists');
validationResult.put('validationDetails', new Map<String, Object>{
'duplicateId' => existingAccounts[0].Id
});
return validationResult;
}
// PASS: All validations passed
validationResult.put('validationStatus', 'PASS');
validationResult.put('validationMessage', 'Customer creation validation passed');
} catch (Exception e) {
// FAIL: Error during validation
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Validation error: ' + e.getMessage());
}
return validationResult;
}
private Boolean isValidCustomerType(String type) {
Set<String> validTypes = new Set<String>{'Customer', 'Prospect', 'Partner'};
return validTypes.contains(type);
}
customiseMutationPayload
This hook modifies the mutation payload before creating a customer record. Use this to add computed fields, set defaults, or transform the payload based on business logic.
Hook Method
Map<String, Object> customiseMutationPayload(Map<String, Object> request, Map<String, Object> context)
Sample Apex Implementation
/**
* Customizes the mutation payload before the GraphQL mutation is executed.
* Reads Description and Industry from the request body in context and adds them
* to the Account node at alias path "customerAccount".
*
* @param request The mutation request payload
* @param context Request context containing API details and request body
* @return Map containing mutation transformation instructions with nodes array:
* - nodes[0]: Contains path='customerAccount' and addFields with Description and Industry
*/
public Map<String, Object> customiseMutationPayload(Map<String, Object> request, Map<String, Object> context) {
// Return mutation transformation instructions: add Account fields at alias path "customerAccount"
Map<String, Object> nodes0 = new Map<String, Object>();
nodes0.put('path', 'customerAccount');
Map<String, Object> addFields = new Map<String, Object>();
// Read Description and Industry from request body in context
Map<String, Object> requestBody = (Map<String, Object>)context.get('requestBody');
if (requestBody != null) {
String description = (String)requestBody.get('description');
String industry = (String)requestBody.get('industry');
// Add Description to Account if present in request
if (description != null) {
addFields.put('Description', description);
}
// Add Industry to Account if present in request
if (industry != null) {
addFields.put('Industry', industry);
}
}
nodes0.put('addFields', addFields);
// Build nodes array containing the transformation instructions
List<Object> nodes = new List<Object>();
nodes.add(nodes0);
// Return result with nodes array
Map<String, Object> result = new Map<String, Object>();
result.put('nodes', nodes);
return result;
}
handlePostOperation
This hook post-processes and transforms the API response after data is deleted.
Hook Method
Map<String, Object> handlePostOperation(Map<String, Object> graphQLQueryResultAsMap, Map<String, Object> constructedTMFResponse, Map<String, Object> context)
Full Implementation Example
/**
* Complete Customer Management POST API Extension
* Demonstrates all three applicable lifecycle hooks with business logic
*/
public class CustomerManagementPOSTExtension implements comms_apex_ext.ICustomerManagementPOST {
/**
* Hook 1: Apply custom validations
*/
public Map<String, Object> applyCustomValidations(Map<String, Object> context) {
Map<String, Object> requestBody = (Map<String, Object>) context.get('requestBody');
Map<String, Object> validationResult = new Map<String, Object>();
try {
String customerName = (String) requestBody.get('name');
String customerType = (String) requestBody.get('type');
// Validate required fields
if (String.isBlank(customerName)) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Customer name is required');
return validationResult;
}
// Validate customer type
if (!isValidCustomerType(customerType)) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Invalid customer type');
return validationResult;
}
// Check for duplicates
List<Account> existingAccounts = [SELECT Id FROM Account WHERE Name = :customerName LIMIT 1];
if (!existingAccounts.isEmpty()) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Customer with this name already exists');
return validationResult;
}
validationResult.put('validationStatus', 'PASS');
validationResult.put('validationMessage', 'Validation passed');
} catch (Exception e) {
validationResult.put('validationStatus', 'FAIL');
validationResult.put('validationMessage', 'Validation error: ' + e.getMessage());
}
return validationResult;
}
/**
* Hook 2: Customize mutation payload
*/
/**
* Customizes the mutation payload before the GraphQL mutation is executed.
* Reads Description and Industry from the request body in context and adds them
* to the Account node at alias path "customerAccount".
*
* @param request The mutation request payload
* @param context Request context containing API details and request body
* @return Map containing mutation transformation instructions with nodes array:
* - nodes[0]: Contains path='customerAccount' and addFields with Description and Industry
*/
public Map<String, Object> customiseMutationPayload(Map<String, Object> request, Map<String, Object> context) {
// Return mutation transformation instructions: add Account fields at alias path "customerAccount"
Map<String, Object> nodes0 = new Map<String, Object>();
nodes0.put('path', 'customerAccount');
Map<String, Object> addFields = new Map<String, Object>();
// Read Description and Industry from request body in context
Map<String, Object> requestBody = (Map<String, Object>)context.get('requestBody');
if (requestBody != null) {
String description = (String)requestBody.get('description');
String industry = (String)requestBody.get('industry');
// Add Description to Account if present in request
if (description != null) {
addFields.put('Description', description);
}
// Add Industry to Account if present in request
if (industry != null) {
addFields.put('Industry', industry);
}
}
nodes0.put('addFields', addFields);
// Build nodes array containing the transformation instructions
List<Object> nodes = new List<Object>();
nodes.add(nodes0);
// Return result with nodes array
Map<String, Object> result = new Map<String, Object>();
result.put('nodes', nodes);
return result;
}
/**
* Hook 3: Post-process response
*/
public Map<String, Object> handlePostOperation(
Map<String, Object> graphQLQueryResultAsMap,
Map<String, Object> constructedTMFResponse,
Map<String, Object> context
) {
return null;
}
/**
* NOT APPLICABLE: configureDefaultValidations is not used for Customer Management API
*/
public Map<String, Boolean> configureDefaultValidations(
Map<String, Boolean> defaultValidationConfiguration,
Map<String, Object> context
) {
return null;
}
private Boolean isValidCustomerType(String type) {
Set<String> validTypes = new Set<String>{'Customer', 'Prospect', 'Partner'};
return validTypes.contains(type);
}
private String determineCustomerSegment(String name) {
if (name.length() > 20) {
return 'Enterprise';
} else if (name.length() > 10) {
return 'Mid-Market';
} else {
return 'SMB';
}
}
**
* NOT APPLICABLE: customiseGraphQLQuery is not used for Customer Management API
*/
public Map<String, Object> customiseGraphQLQuery(
Map<String, Object> graphQLAsMap,
Map<String, Object> context
) {
return null;
}
}
GraphQL Mutation - Create Operations
Create mutations add new records and return the created record with the specified output fields.
Create Enhancements: Add Output Fields
Original Mutation (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: { Name: "Acme Corp" }
}) {
Record {
Id
Name { value }
}
}
}
}
Transformation Instructions (JSON):
{
"nodes": [{
"path": "customerAccount",
"addFields": {
"Industry": "Technology",
"Revenue": 5000000,
"Status": "Active"
}
}]
}
Result (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: { Name: "Acme Corp" }
}) {
Record {
Id
Name { value }
Industry
Revenue
Status
}
}
}
}
Create Enhancements: Modify Input Payload
Original Mutation (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: { Name: "Acme Corp" }
}) {
Record {
Id
Name { value }
}
}
}
}
Transformation Instructions (JSON - Modify Input):
{
"nodes": [{
"path": "customerAccount",
"modifyInput": {
"addInputFields": {
"Industry": "Technology",
"Status": "Active"
}
}
}]
}
Result (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: {
Name: "Acme Corp",
Industry: "Technology",
Status: "Active"
}
}) {
Record {
Id
Name { value }
}
}
}
}
note: Using modifyInput with addInputFields adds new fields to the input payload. These fields are added to the Account object within the input wrapper and are sent to the mutation.
Create Enhancements: Modify Existing Input Fields
Original Mutation (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: { Name: "Acme Corp" }
}) {
Record {
Id
Name { value }
}
}
}
}
Transformation Instructions (JSON - Modify Existing Fields):
{
"nodes": [{
"path": "customerAccount",
"modifyInput": {
"inputModifications": {
"Name": "Updated Company Name"
}
}
}]
}
Result (GraphQL):
mutation CreateCustomerAndRelatedEntities {
uiapi {
customerAccount: AccountCreate(input: {
Account: { Name: "Updated Company Name" }
}) {
Record {
Id
Name { value }
}
}
}
}
note: The inputModifications replaces the values of existing input fields. The transformer identifies the wrapper key, for example Account and applies the changes at the correct nested level.