Loading
The online Trailblazer Community becomes read-only Oct 30, 2026Read More
Media Cloud
Apex-Based Integration Definition for Ad Sales Business Processes

Apex-Based Integration Definition for Ad Sales Business Processes

The standard provider that's comes with Advertising Sales Management send a fixed set of advertisement campaign order information to external systems. System integrators can create an Apex-based integration definition to send ad sales order information that's customized to the requirements of the publisher to their external systems.

Required Editions

Available in: Lightning Experience
Available in: Enterprise, Performance, and Unlimited editions with Media Cloud - Advanced

Required Configuration of Apex-Based Integration Definition

The Apex-based integration definition that system integration creates uses multiple Advertising Sales Management resources to get the publisher's ad sales data that must be sent to external systems. To ensure that the Advertising Sales Management resources are able to uniquely identify the standard integration definition, make sure that the developer name is AdServerIntegrationForAdSalesManagement.

Reference Apex Class

The reference Apex class is based on the AdServerIntegrationProvider standard provider. When a system integrator uses the reference Apex class without any changes, the attributes of the integration definition are the same as the ones for the standard integration definition.

global class SfiAdsAdServerIntegrationProvider implements industriesintegrationfwk.ProcessIntegrationProvider {

    private static final Map<String,String> INTEGRATION_ACTION_TO_HTTP_METHOD = new Map<String,String>{
        'CHECK_AVAILABILITY' => 'POST',
        'CREATE_ORDERS' => 'POST',
        'CREATE_LINE_ITEMS' => 'POST',
        'UPDATE_LINE_ITEMS' => 'PUT',
        'PERFORM_ORDER_ACTION' => 'POST'
    };
    
    global static industriesintegrationfwk.IntegrationCalloutResponse executeCallout(String requestGuid, String inputRecordId, String payload, Map<String, Object> attributes) {
    

        String namedCred = (String) attributes.get('NAMED_CREDENTIAL');
        System.debug('#### namedCred = ' + namedCred);
        
        Integer timeout = (Integer) attributes.get('API_TIMEOUT');
        System.debug('#### timeout = ' + timeout);
        
        System.debug('#### asm integration request = ' + JSON.serialize(payload));
        
        Map<String, Object> asmIntegrationRequest = (Map<String, Object>) JSON.deserializeUntyped(payload);
        String integrationAction = (String) asmIntegrationRequest.get('action');
        System.debug('#### integrationAction = ' + integrationAction);
        String apiPath = getApiPath(integrationAction, attributes);

        
        String requestBody = (String) asmIntegrationRequest.get('payload');
        System.debug('#### Request payload = ' + requestBody);

        String endpoint = 'callout:' + namedCred + apiPath;
        
        String httpMethod = INTEGRATION_ACTION_TO_HTTP_METHOD.get(integrationAction);
        
        // create http request
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setEndpoint(endpoint);
        httpRequest.setMethod(httpMethod);
        httpRequest.setBody(requestBody);
        httpRequest.setTimeout(timeout);
        httpRequest.setHeader('Content-Type', 'application/json');
        
        // make callout
        Http http = new Http();
        HttpResponse httpResponse = http.send(httpRequest);
        System.debug('#### httpResponse = ' + httpResponse);
        
        String responseBody = httpResponse.getBody();
        Integer statusCode = httpResponse.getStatusCode();
        
        System.debug('#### response body = ' + responseBody);
        System.debug('#### response status code = ' + statusCode);
        
        Map<String, Object> returnValue = (Map<String, Object>) JSON.deserializeUntyped(responseBody);
        
    
        // initialize response
        industriesintegrationfwk.IntegrationCalloutResponse integrationCalloutResponse = new industriesintegrationfwk.IntegrationCalloutResponse(true);
        integrationCalloutResponse.setReturnValue(returnValue);
        integrationCalloutResponse.setResponseCode(statusCode);
        
        return integrationCalloutResponse;
    }
    
     global static List<industriesintegrationfwk.ApexProviderAttr> getProviderAttributes() {
         
        // Named cred
        industriesintegrationfwk.ApexProviderAttr namedCred = new industriesintegrationfwk.ApexProviderAttr('Named Credential', 'NAMED_CREDENTIAL', '', false, 'String');
        
        //  timeout
        industriesintegrationfwk.ApexProviderAttr timeout = new industriesintegrationfwk.ApexProviderAttr('Timeout (milliseconds)', 'API_TIMEOUT', '', false, 'Integer');
         
        // content type
        industriesintegrationfwk.ApexProviderAttr contentType = new industriesintegrationfwk.ApexProviderAttr('Content-Type', 'CONTENT_TYPE', '', false, 'String');
        
        // Check availability Api Path
        industriesintegrationfwk.ApexProviderAttr checkAvailApiPath = new industriesintegrationfwk.ApexProviderAttr('Check Availability API Path', 'CHECK_AVAILABILITY_API_PATH', '', false, 'String');
         
        // create order Api Path
        industriesintegrationfwk.ApexProviderAttr createOrderApiPath = new industriesintegrationfwk.ApexProviderAttr('Create Order API Path', 'CREATE_ORDER_API_PATH', '', false, 'String');
         
        // create order line item Api Path
        industriesintegrationfwk.ApexProviderAttr createOrderLineItemsApiPath = new industriesintegrationfwk.ApexProviderAttr('Create Line Items API Path', 'CREATE_LINE_ITEMS_API_PATH', '', false, 'String');
         
        // update order line item Api Path
        industriesintegrationfwk.ApexProviderAttr updateOrderLineItemsApiPath = new industriesintegrationfwk.ApexProviderAttr('Update Line Items API Path', 'UPDATE_LINE_ITEMS_API_PATH', '', false, 'String');
         
        // perform order action Api Path
        industriesintegrationfwk.ApexProviderAttr performOrderActionApiPath = new industriesintegrationfwk.ApexProviderAttr('Perform Order Action API Path', 'PERFORM_ORDER_ACTION_API_PATH', '', false, 'String');
 

        List<industriesintegrationfwk.ApexProviderAttr> defaults = new List<industriesintegrationfwk.ApexProviderAttr>();
        defaults.add(namedCred);
        defaults.add(timeout);
        defaults.add(contentType);
        defaults.add(checkAvailApiPath);
        defaults.add(createOrderApiPath);
        defaults.add(createOrderLineItemsApiPath);
        defaults.add(updateOrderLineItemsApiPath);
        defaults.add(performOrderActionApiPath);
        
        return defaults;
    }

    global static String getApiPath(String integrationAction, Map<String, Object> attributes) {

        String apiPath = null;

        if(integrationAction == 'CHECK_AVAILABILITY') {
            apiPath =  (String) attributes.get('CHECK_AVAILABILITY_API_PATH');
        } else if(integrationAction == 'CREATE_ORDERS') {
            apiPath =  (String) attributes.get('CREATE_ORDER_API_PATH');
        } else if(integrationAction == 'CREATE_LINE_ITEMS') {
            apiPath =  (String) attributes.get('CREATE_LINE_ITEMS_API_PATH');
        } else if (integrationAction == 'UPDATE_LINE_ITEMS') {
            apiPath =  (String) attributes.get('UPDATE_LINE_ITEMS_API_PATH');
        } else if (integrationAction == 'PERFORM_ORDER_ACTION') {
            apiPath =  (String) attributes.get('PERFORM_ORDER_ACTION_API_PATH');
        }
        return apiPath;
    }
}
 
Loading
Salesforce Help | Article