Apex Type Provider

Implement custom integration logic via Apex by using the Apex Type Provider. This provider requires an Apex Integration Developer to implement a custom Apex adapter interface.

Use a custom Apex adapter to:

  • Include and use integration parameters in adapter implementations such as timeouts, credentials, and path.
  • Generate and transform requests and responses via Omnistudio Integration Procedures or Extract, Transform, Load (ETL) libraries.
  • Enable asynchronous interaction pattern.
  • Enable request and response logging by implementing a specific Apex interface.
  • Handle errors, and integrate with fallout rules.

To ‌configure the callout settings for Apex Type Provider, see Configuration Steps.

Integration Adapter Implementation 

Implement the industriesintegrationfwk.ProcessIntegrationProvider Apex interface. Use the industriesintegrationfwk.ApexProviderAttr class to define and access the attribute values in the integration provider definition.

1global with sharing class DROSampleOrderAdapter implements industriesintegrationfwk.ProcessIntegrationProvider {
2    
3    // Named credential attribute
4    private static final String MOCK_CALLOUT_NAMED_CREDENTIAL = 'callout:DROOrderInterfaceNamedCred';
5    private final static Integer TIMEOUT = 10000; // Request timeout in milliseconds, or can be defined on Integration Definition as an Attribute
6    
7    
8    private static final industriesintegrationfwk.ApexProviderAttr NAMED_CRED_ATTR = new industriesintegrationfwk.ApexProviderAttr('Named Credential', 
9    'Named_Credential', 'DROOrderInterfaceNamedCred', true, 'String');
10    private static final industriesintegrationfwk.ApexProviderAttr ENDPOINT_ATTR = new industriesintegrationfwk.ApexProviderAttr('Endpoint URI', 
11    'Endpoint_URI', '/v1/orderitems/', true, 'String');
12
13    
14    /**
15     * @param requestGuid                 Request Globally Unique Identifier (GUID) provided by the client
16     * @param inputRecordId               Input Record ID — value is taken from Fulfillment Step > Fulfillment Step Source > Source Line Item
17     * @param payload                     Payload to be passed to the Provider Class (empty in DRO)
18     * @param attributes                  Map of configuration attributes
19     * @return IntegrationCalloutResponse Response sent to the client
20    */
21    global static industriesintegrationfwk.IntegrationCalloutResponse executeCallout(String requestGuid, String inputRecordId, String payload, Map<String, Object> attributes) {
22        // create request
23        String msgBody = '{\"message\":\"Hello\",' 
24            + '\n\"requestGuid\":\"' + requestGuid + '\",\n'
25            + '\n\"inputRecordId\":\"' + inputRecordId + '\",\n'
26            + '\n\"payload\":\"' + payload + '\"}'            
27            ;
28        
29        String endpointUri = (String) attributes.get('Endpoint_URI');
30
31        // Make a call
32        HttpResponse response = makeCallout(endpointUri, msgBody);
33        // process response and pass details to the DRO Callout Step processor by using IntegrationCalloutResponse(isSuccess, ResponseCode, ErrorMessage)
34 
35         industriesintegrationfwk.IntegrationCalloutResponse integrationCalloutResponse = handleResponse(response); 
36
37        return integrationCalloutResponse;
38    }
39
40    // define configurable attriobutes 
41    global static List<industriesintegrationfwk.ApexProviderAttr> getProviderAttributes() {
42        List<industriesintegrationfwk.ApexProviderAttr> defaults = new List<industriesintegrationfwk.ApexProviderAttr>();
43        defaults.add(NAMED_CRED_ATTR);
44        defaults.add(ENDPOINT_ATTR);
45        // add any attributes such as endpoint, timeout, interface, and params
46        // ...
47        return defaults;
48    }   
49
50    // Call Mock Service API.
51    private static HttpResponse makeCallout(String endpointUri, String msgBody) {
52        
53        // Construct the request object
54        String endPoint = MOCK_CALLOUT_NAMED_CREDENTIAL + endpointUri;
55        HttpRequest request = new HttpRequest();
56        request.setMethod('POST');
57        request.setHeader('Content-Type', 'application/json');
58        request.setHeader('Accept', 'application/json');
59        request.setEndpoint(endPoint);
60        request.setTimeout(TIMEOUT);
61        request.setBody(msgBody);
62        
63        // Send request
64        HttpResponse response = new Http().send(request);
65        return response;
66    }
67}

Error Handling 

This sample shows how to pass errors from response to orchestration via the IntegrationResponse interface in the Apex provider implementation. See ProcessIntegrationProvider Interface.

1public static industriesintegrationfwk.IntegrationCalloutResponse handleResponse(HttpResponse response) { 
2    
3        industriesintegrationfwk.IntegrationCalloutResponse integrationCalloutResponse;
4        
5        Map<String, Object> responseGroup = getResponseGroupAfterCallout(response);
6        
7        if(response.getStatusCode() == 200)
8        {
9            // SUCCESS
10            integrationCalloutResponse = new industriesintegrationfwk.IntegrationCalloutResponse(true);
11                    integrationCalloutResponse.setResponseCode(response.getStatusCode());
12              integrationCalloutResponse.setReturnValue(responseGroup);
13        
14        } else {
15            //FAILURE - pass error to DRO Fallout Handling to apply Retry Policies
16            integrationCalloutResponse = new industriesintegrationfwk.IntegrationCalloutResponse(false);
17            integrationCalloutResponse.setResponseCode(response.getStatusCode());
18            integrationCalloutResponse.setReturnValue(responseGroup);
19            integrationCalloutResponse.setErrorMessage('Unable to process request.');
20        }
21        return integrationCalloutResponse;
22        }
23    
24    // Process Response payLoad 
25    private static Map<String, Object> getResponseGroupAfterCallout(HttpResponse response) {
26        Map<String, Object> responseGroup = new Map<String, Object>();
27        if (response.getStatusCode() == 200) {
28            responseGroup.put('isSuccess', true);
29        } else {
30            responseGroup.put('isSuccess', false);
31        }
32        responseGroup.put('response', getResponseMap(response.getBody()));
33        return responseGroup;
34    }
35    
36    // Convert response string into Map 
37    private static Map<String,Object> getResponseMap(String responseBody) {
38        try {
39            Map<String,Object> responseBodyMap = (Map<String,Object>) JSON.deserializeUntyped(responseBody);
40            return responseBodyMap;
41        } catch (Exception e) {
42            Map<String, Object> responseMap = new Map<String,Object>();
43            responseMap.put('response', responseBody);
44            return responseMap;
45        }
46    }

The fulfillment step state changes to Fatally Failed, and the error message is saved in the Execution Message field.

A change of state in the Filfillment Step record page with Apex Service Type Provider.

A change of state in the Filfillment Plan record page with Apex Service Type Provider.

Apex Advanced Interface Implementation 

To use advanced features such as logging, the Apex provider must implement the Apex Provider Advanced interface. You must use the HttpBaseProvider client for HTTP requests.

This example shows a sample of the ProcessIntegrationProviderAdvanced Apex interface implementation.

1global with sharing class DFOApexVlocMockWithDelay
2implements industriesintegrationfwk.ProcessIntegrationProviderAdvanced {
3...
4global static industriesintegrationfwk.IntegrationCalloutResponse executeCallout(String requestGuid, String inputRecordId, String payload, Map<String, Object> attributes,
5industriesintegrationfwk.HttpBaseProvider httpProvider) {
6...
7String endPoint = MOCK_CALLOUT_NAMED_CREDENTIAL + '/delay/5';
8HttpRequest request = new HttpRequest();
9request.setMethod('POST');
10request.setHeader('Content-Type', 'application/json');
11request.setHeader('Accept', 'application/json');
12request.setEndpoint(endPoint);
13request.setTimeout(TIMEOUT);
14request.setBody(msgBody);
15
16// Send request
17//HttpResponse response = httpProvider.httpCallout(request);
18HttpResponse response = new Http().send(request);

Integration Definition Configuration 

Select the Save the request and response as attachments to the record checkbox for the integration definition to save request and response payloads as attachments to the Integration Provider Execution record. Content publish limits apply when saving request and response payloads as attachments. Use Shield Platform Encryption for secure storage of sensitive information.

See Create an Integration Definition.

Log Records 

Integration Provider execution records are created on every request and associated with the fulfillment step. The referenced object identifier is set to order item or fulfillment order line item ID. SeeIntegrationProviderExecution.

To view the Integration Provider execution records, configure the Fulfillment Step record page to include the Integration Provider Executions related list by using Lightning App Builder. See Lightning App Builder.

The Lightning App Builder page to add the Integration Provider Executions related list to the Fulfillment Step record page.