ICustomerManagementGET Apex Interface

The ICustomerManagementGET Apex interface provides extensibility for TMF629 GET 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 interface supports the following hooks.

The configureDefaultValidations hook is not used for the Customer Management API. If implemented, the method may be invoked, but its return values are ignored.

Note

Retrieval Lifecycle Use Cases and Hook Mapping 

This table lists common use cases and the hooks required for the GET operation.

Use CaseHook(s)Description
Example Scenarios
Benefit
Role-Based Data FilteringapplyCustomValidations, handlePostOperationEnforces access rules by validating user permissions before execution and filtering sensitive data after retrieval. Supports role-based visibility at field and record levels.• Restrict access to VIP or high-value customer profiles• Hide sensitive fields (e.g., credit score) for frontline agents• Enforce region-based access boundariesStrengthens data governance and ensures secure, compliant access to customer data
Custom Field EnrichmenthandlePostOperationAdds calculated or derived fields to API responses without changing the base TMF schema, allowing customers to extend or modify as needed. Enables enrichment using internal business rules or external systems.• Add customer health score• Flag “preferred customer” status• Include aggregated financial or usage insightsDelivers richer, more contextual responses while preserving TMF schema integrity
Dynamic Query CustomizationcustomiseGraphQLQueryModifies GraphQL queries dynamically based on client or request context by adding fields, filters, or transformations.• Mobile app requests only essential fields• Portal requires additional entitlement or hierarchy fields• Apply filters automatically for partner channelsSupports diverse client requirements using a single API and reduces need for API versioning
Business Rule ValidationapplyCustomValidationsApplies business and eligibility rules before processing requests, stopping invalid operations early in the lifecycle.• Ensure customer is “active” before retrieving services• Reject unauthorized or unverified channel requests• Enforce lifecycle or dependency checksProvides strong business consistency and reduces downstream errors by blocking invalid requests early

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 

1public Map<String, Object> transformRequest(Map<String, Object> context) {
2       if (context == null) {
3           return context;
4       }
5
6       Object idObj = context.get('id');
7       if (idObj == null || !(idObj instanceof String)) {
8           return context;
9       }
10
11       String idValue = (String)idObj;
12
13       // Check if the ID looks like a Salesforce ID (starts with 001, 003, etc.)
14       // If not, assume it's an AccountNumber and resolve it
15       if (idValue.length() == 15 || idValue.length() == 18) {
16           // Looks like a Salesforce ID, return context as-is
17           return context;
18       }
19
20       // Query Account objects where AccountNumber matches the provided ID
21       List<Account> accounts = [
22           SELECT Id, AccountNumber
23           FROM Account
24           WHERE AccountNumber = :idValue
25           LIMIT 1
26       ];
27
28       // If found, replace the ID in context with the Salesforce ID
29       if (!accounts.isEmpty() && accounts[0].AccountNumber != null) {
30           context.put('id', accounts[0].Id);
31       }
32
33       return context;
34   }

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 

1public Map<String, Object> applyCustomValidations(Map<String, Object> context) {
2       // Input context:
3       // {
4       //   api: 'CustomerManagement',
5       //   version: '4.0',
6       //   customerId: '001xx000003DHP',
7       //   userId: '005xx000001Sv5',
8       //   requiredFields: ['Id', 'Name']
9       // }
10
11       String customerId = (String) context.get('customerId');
12       String userId = (String) context.get('userId');
13
14       Map<String, Object> validationResult = new Map<String, Object>();
15
16       try {
17           // Check if user has access to this customer
18           User currentUser = [SELECT Id, Profile.Name FROM User WHERE Id = :userId LIMIT 1];
19           Account customer = [SELECT Id, BillingCountry FROM Account WHERE Id = :customerId LIMIT 1];
20
21           if ('Customer Service Rep'.equals(currentUser.Profile.Name)) {
22               // Validate customer is in allowed region
23               if ('US'.equals(customer.BillingCountry)) {
24                   // PASS: User has access
25                   validationResult.put('validationStatus', 'PASS');
26                   validationResult.put('validationMessage', 'User has access to this customer');
27               } else {
28                   // FAIL: User does not have access to this region
29                   validationResult.put('validationStatus', 'FAIL');
30                   validationResult.put('validationMessage', 'User does not have access to customers in this region');
31                   validationResult.put('validationDetails', new Map<String, Object>{
32                       'denialReason' => 'REGION_RESTRICTION',
33                       'userRegion' => 'US',
34                       'customerRegion' => customer.BillingCountry
35                   });
36               }
37           } else {
38               // PASS: Other profiles have unrestricted access
39               validationResult.put('validationStatus', 'PASS');
40               validationResult.put('validationMessage', 'User profile has unrestricted access');
41           }
42       } catch (Exception e) {
43           // FAIL: Error during validation
44           validationResult.put('validationStatus', 'FAIL');
45           validationResult.put('validationMessage', 'Validation error: ' + e.getMessage());
46           validationResult.put('validationDetails', new Map<String, Object>{
47               'errorType' => e.getTypeName()
48           });
49       }
50
51       // Return validation result directly (not wrapped in 'result' key)
52       return validationResult;
53   }

customiseGraphQLQuery 

This hook modifies the GraphQL query before execution to add fields, filters, or transformations. Returns a map with a spec key containing a list of QueryTransformationNode objects.

Hook Method 

Map<String, Object> customiseGraphQLQuery(Map<String, Object> graphQLAsMap, Map<String, Object> context)

Sample Apex Implementation 

1public Map<String, Object> customiseGraphQLQuery(
2        Map<String, Object> graphQLAsMap,
3        Map<String, Object> context
4    ) {
5        // Create transformation specification to add custom fields and filters
6        List<Map<String, Object>> transformationNodes = new List<Map<String, Object>>();
7
8        // Node 1: Add custom fields to the Account node
9        // Path: uiapi.query.Account (the Account field in the GraphQL query)
10        Map<String, Object> addFieldsNode = new Map<String, Object>{
11            'path' => 'uiapi.query.Account',
12            'addFields' => new List<String>{'CustomField__c', 'IndustrySegment__c', 'Status'}
13        };
14        transformationNodes.add(addFieldsNode);
15
16        // Node 2: Add filters to the Account query
17        // Only retrieve active accounts
18        Map<String, Object> filterNode = new Map<String, Object>{
19            'path' => 'uiapi.query.Account',
20            'addFilters' => new Map<String, Object>{
21                'clearExistingFilters' => false,
22                'filterGraphQlSnippet' => '{ Status: { eq: "Active" } }'
23            }
24        };
25        transformationNodes.add(filterNode);
26
27        // Return transformation specification
28        return new Map<String, Object>{
29            'spec' => transformationNodes
30        };
31    }

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 

1public Map<String, Object> handlePostOperation(
2        Map<String, Object> graphQLQueryResultAsMap,
3        Map<String, Object> constructedTMFResponse,
4        Map<String, Object> context
5    ) {
6        // Input GraphQL result:
7        // {
8        //   items: [{ Id: '001xx000003DHP', Name: 'Acme', AnnualRevenue: 5000000 }],
9        //   count: 1
10        // }
11
12        // Input TMF response:
13        // {
14        //   customer: [{ id: '001xx000003DHP', name: 'Acme', type: 'Customer' }]
15        // }
16
17        List<Object> customerList = (List<Object>) constructedTMFResponse.get('customer');
18
19        if (customerList != null && !customerList.isEmpty()) {
20            for (Object customerObj : customerList) {
21                Map<String, Object> customer = (Map<String, Object>) customerObj;
22                String customerId = (String) customer.get('id');
23
24                // Fetch additional data for enrichment
25                Account acc = [SELECT Id, AnnualRevenue, NumberOfEmployees FROM Account WHERE Id = :customerId LIMIT 1];
26
27                // Add calculated fields
28                if (acc.AnnualRevenue != null) {
29                    String revenueSegment = acc.AnnualRevenue > 10000000 ? 'Enterprise' : 'Mid-Market';
30                    customer.put('revenueSegment', revenueSegment);
31                }
32
33                if (acc.NumberOfEmployees != null) {
34                    customer.put('employeeCount', acc.NumberOfEmployees);
35                }
36
37                // Add audit information
38                customer.put('lastRetrievedAt', DateTime.now().format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\''));
39                customer.put('retrievedBy', UserInfo.getName());
40            }
41        }
42
43        // Return enriched response
44        return constructedTMFResponse;
45
46        // Output response:
47        // {
48        //   customer: [{
49        //     id: '001xx000003DHP',
50        //     name: 'Acme',
51        //     type: 'Customer',
52        //     revenueSegment: 'Enterprise',
53        //     employeeCount: 500,
54        //     lastRetrievedAt: '2024-01-15T10:30:00Z',
55        //     retrievedBy: 'John Smith'
56        //   }]
57        // }
58    }

Full Implementation Example 

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

1/**
2 * Complete Customer Management GET API Extension
3 * Demonstrates all three applicable lifecycle hooks with business logic
4 */
5public class CustomerManagementGETExtension implements comms_apex_ext.ICustomerManagementGET {
6
7    /**
8     * Hook 1: Apply custom validations
9     */
10    public Map<String, Object> applyCustomValidations(Map<String, Object> context) {
11        String customerId = (String) context.get('customerId');
12        String userId = (String) context.get('userId');
13
14        Map<String, Object> validationResult = new Map<String, Object>();
15
16        try {
17            User currentUser = [SELECT Id, Profile.Name FROM User WHERE Id = :userId LIMIT 1];
18            Account customer = [SELECT Id, BillingCountry FROM Account WHERE Id = :customerId LIMIT 1];
19
20            if ('Customer Service Rep'.equals(currentUser.Profile.Name)) {
21                if ('US'.equals(customer.BillingCountry)) {
22                    validationResult.put('validationStatus', 'PASS');
23                    validationResult.put('validationMessage', 'User has access to this customer');
24                } else {
25                    validationResult.put('validationStatus', 'FAIL');
26                    validationResult.put('validationMessage', 'Access denied - customer region not allowed');
27                    validationResult.put('validationDetails', new Map<String, Object>{
28                        'denialReason' => 'REGION_RESTRICTION'
29                    });
30                }
31            } else {
32                validationResult.put('validationStatus', 'PASS');
33                validationResult.put('validationMessage', 'User profile has unrestricted access');
34            }
35        } catch (Exception e) {
36            validationResult.put('validationStatus', 'FAIL');
37            validationResult.put('validationMessage', 'Validation error: ' + e.getMessage());
38        }
39
40        return validationResult;
41    }
42
43    /**
44     * Hook 2: Customize GraphQL query
45     * Uses transformation syntax from GRAPHQL_QUERY_TRANSFORMATION.md
46     */
47    public Map<String, Object> customiseGraphQLQuery(
48        Map<String, Object> graphQLAsMap,
49        Map<String, Object> context
50    ) {
51        List<Map<String, Object>> transformationNodes = new List<Map<String, Object>>();
52
53        // Add custom fields to the Account node
54        // Path: uiapi.query.Account (the Account field in the GraphQL query)
55        transformationNodes.add(new Map<String, Object>{
56            'path' => 'uiapi.query.Account',
57            'addFields' => new List<String>{'CustomField__c', 'IndustrySegment__c', 'Status'}
58        });
59
60        // Add filters to the Account query
61        // Only retrieve active accounts
62        transformationNodes.add(new Map<String, Object>{
63            'path' => 'uiapi.query.Account',
64            'addFilters' => new Map<String, Object>{
65                'clearExistingFilters' => false,
66                'filterGraphQlSnippet' => '{ Status: { eq: "Active" } }'
67            }
68        });
69
70        return new Map<String, Object>{ 'spec' => transformationNodes };
71    }
72
73    /**
74     * Hook 3: Post-process response
75     */
76    public Map<String, Object> handlePostOperation(
77        Map<String, Object> graphQLQueryResultAsMap,
78        Map<String, Object> constructedTMFResponse,
79        Map<String, Object> context
80    ) {
81        List<Object> customerList = (List<Object>) constructedTMFResponse.get('customer');
82
83        if (customerList != null) {
84            for (Object customerObj : customerList) {
85                Map<String, Object> customer = (Map<String, Object>) customerObj;
86                String customerId = (String) customer.get('id');
87
88                try {
89                    Account acc = [SELECT Id, AnnualRevenue FROM Account WHERE Id = :customerId LIMIT 1];
90
91                    if (acc.AnnualRevenue != null) {
92                        customer.put('revenueSegment', acc.AnnualRevenue > 10000000 ? 'Enterprise' : 'Mid-Market');
93                    }
94                } catch (Exception e) {
95                    System.debug('Error enriching customer data: ' + e.getMessage());
96                }
97            }
98        }
99
100        return constructedTMFResponse;
101    }
102    /**
103     * NOT APPLICABLE: configureDefaultValidations is not used for Customer Management API
104     * If implemented, this method will be invoked but return values will be ignored.
105     */
106    public Map<String, Boolean> configureDefaultValidations(
107        Map<String, Boolean> defaultValidationConfiguration,
108        Map<String, Object> context
109    ) {
110        // This hook is not applicable for Customer Management API
111        // Return the configuration unchanged
112        return defaultValidationConfiguration;
113    }
114}

Response Structure 

Single Customer Response (GraphQL) 

1{
2  "id": "001xx000003DHP",
3  "name": "Acme Corporation",
4  "type": "Customer",
5  "href": "/services/data/v60.0/sobjects/Account/001xx000003DHP",
6  "account": [
7    {
8      "id": "001xx000003DHQ",
9      "name": "Acme East Division",
10      "type": "Account",
11      "href": "/services/data/v60.0/sobjects/Account/001xx000003DHQ",
12      "description": "Eastern regional division"
13    }
14  ],
15  "contactMedium": [
16    {
17      "mediumType": "Email",
18      "characteristic": {
19        "contactType": "Email",
20        "emailAddress": "contact@acme.com"
21      }
22    },
23    {
24      "mediumType": "Phone",
25      "characteristic": {
26        "contactType": "Phone",
27        "phoneNumber": "+1-555-0100"
28      }
29    }
30  ],
31  "engagedParty": {
32    "id": "003xx000004MZZ",
33    "name": "John Smith",
34    "role": "Individual",
35    "href": "/services/data/v60.0/sobjects/Contact/003xx000004MZZ"
36  },
37  "agreement": [
38    {
39      "id": "800xx000000001",
40      "name": "Service Agreement 2024",
41      "href": "/services/data/v60.0/sobjects/Contract/800xx000000001"
42    }
43  ]
44}

List Response (GraphQL) 

1{
2  "recordList": [
3    {
4      "id": "001xx000003DHP",
5      "name": "Acme Corporation",
6      "type": "Customer",
7      "href": "/services/data/v60.0/sobjects/Account/001xx000003DHP"
8    },
9    {
10      "id": "001xx000003DHQ",
11      "name": "TechCorp Inc",
12      "type": "Customer",
13      "href": "/services/data/v60.0/sobjects/Account/001xx000003DHQ"
14    }
15  ],
16  "pageInfo": {
17    "startCursor": "YXJyYXljb25uZWN0aW9uOjA=",
18    "endCursor": "YXJyYXljb25uZWN0aW9uOjE="
19  }
20}

GraphQL Query Transformations 

Query transformations provide the ability to enhance GraphQL queries by adding fields, applying filters, or modifying the sort order, while preserving the original query definition.

For the Customer Management API, use the uiapi.query.Account path to reference the primary Account field.

Note

Query Enhancements: Fields and Filters 

Original Query (GraphQL):

1query {
2myAccounts: accounts {
3id
4name
5}
6}

Transformation Instructions (JSON):

1{
2"nodes": [
3{
4"path": "myAccounts",
5"addFields": ["email", "phone"],
6"addFilters": {
7"clearExistingFilters": true,
8"filterGraphQlSnippet": "{ status: { eq: \"ACTIVE\" } }"
9}
10}
11]
12}

Result (GraphQL):

1query {
2myAccounts: accounts(where: { status: { eq: "ACTIVE" } }) {
3id
4name
5email
6phone
7}
8}

Query Enhancements: Fields, Filters, and Ordering 

Original Query (GraphQL):

1query {
2myAccounts: accounts {
3id
4name
5}
6}

Transformation Instructions (JSON):

1{
2"nodes": [
3{
4"path": "myAccounts",
5"addFields": ["revenue", "industry"],
6"addFilters": {
7"clearExistingFilters": true,
8"filterGraphQlSnippet": "{
9and: [
10{ status: { eq: \"ACTIVE\" } },
11{ revenue: { gte: 1000000 } }
12]
13}"
14},
15"orderBy": {
16"clearExistingOrderBy": true,
17"orderGraphQlSnippet": "{ revenue: { order: DESC } }"
18}
19}
20]
21}

Result (GraphQL):

1query {
2myAccounts: accounts(
3where: {
4and: [
5{ status: { eq: "ACTIVE" } },
6{ revenue: { gte: 1000000 } }
7]
8},
9orderBy: { revenue: { order: DESC } }
10) {
11id
12name
13revenue
14industry
15}
16}

Query Enhancements: Multiple Query Paths with Different Transformations 

Original Query (GraphQL):

1query {
2myAccounts: accounts {
3id
4name
5myContacts: contacts {
6id
7name
8}
9}
10}

Transformation Instructions (JSON):

1{
2"nodes": [
3{
4"path": "myAccounts",
5"addFields": ["email"],
6"addFilters": {
7"clearExistingFilters": true,
8"filterGraphQlSnippet": "{ status: { eq: \"ACTIVE\" } }"
9}
10},
11{
12"path": "myAccounts.myContacts",
13"addFields": ["email", "phone"],
14"orderBy": {
15"clearExistingOrderBy": true,
16"orderGraphQlSnippet": "{ name: { order: ASC } }"
17}
18}
19]
20}

Result (GraphQL):

1query {
2myAccounts: accounts(where: { status: { eq: "ACTIVE" } }) {
3id
4name
5email
6myContacts: contacts(orderBy: { name: { order: ASC } }) {
7id
8name
9email
10phone
11}
12}
13}

Query Enhancements: Fields and Snippets 

Original Query (GraphQL):

1query {
2myAccounts: accounts {
3id
4name
5}
6}

Transformation Instructions (JSON):

1{
2"nodes": [
3{
4"path": "myAccounts",
5"addFields": ["email"]
6},
7{
8"path": "metrics",
9"insertGraphQlSnippet": "{
10metrics: systemMetrics {
11totalCount
12activeCount
13lastSyncTime
14}
15}"
16}
17]
18}

Result (GraphQL):

1query {
2myAccounts: accounts {
3id
4name
5email
6}
7metrics: systemMetrics {
8totalCount
9activeCount
10lastSyncTime
11}
12}