Diagnostic Tool for Standard Cart APIs

Users can invoke the diagnostic tool for Standard Cart APIs remotely. The TelcoAdminConsoleController supports following types of remote calls for diagnostic APIs.

  • getDiagnosticDetailsreturns a list of string (name of diagnostics to be performed). No parameter is required.
  • executeDiagnostics executes the diagnostic and returns the result of diagnostic in output. Requires name of the diagnostic as diagnosticName parameter.

Below is a sample code, which performs the diagnostic remotely and generates the output in apex debug log files.

vlocity_cmt.TelcoAdminConsoleController controller = new vlocity_cmt.TelcoAdminConsoleController();

// get list of all diagnostics
Map<String, Object> output = controller.invokeMethod('getDiagnosticDetails', new Map<String, String>());


List<Object> diagnosticNames = (List<Object>) output.get('result');

List<Map<String, Object>> results = new List<Map<String, Object>>();

// iterate over the diagnostic list and execute each one
for(Object diagnosticName: diagnosticNames) {

    Map<String, Object> diagOutput = controller.invokeMethod('executeDiagnostics', new Map<String, String>{'diagnosticName'=> (String) diagnosticName});

    Map<String, Object> result = (Map<String, Object>) diagOutput.get('result');

    if(result != null) {
        // if there's a validationMessage, collect the diagnostic result and print in the end
        if(result.get('validationMessage') != null) {
            results.add(result);
        }
    }
}

for(Map<String, Object> result: results) {
    System.debug('--------');
    System.debug('Validation Type: ' + result.get('validationType'));
    System.debug(result.get('validationMessage'));
    System.debug(result.get('howToFix'));
    System.debug('--------');
}

Sample Output: Diagnostic Output

Adding Pre/Post Hook on Standard Cart API Diagnostic Tool APIs

To add pre/post hook logic on the diagnostic APIs, create an interface record with name StdCartDiagnosticHook and create an interface implementation with a custom class as the implementation.

Sample Custom Class:

public with sharing class CustomDiagClass implements vlocity_cmt.VlocityOpenInterface {

    public Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options) {

        if(methodName.equals('getDiagnosticDetails.PostInvoke')) {

            List<Object> diagnosticList = (List<Object>) output.get('result');

            // add the name of custom diagnostic to the list of diagnostics to be performed
            if(diagnosticList != null)
            {
                diagnosticList.add('customDataValidation');
            }
        }
        else if(methodName.equals('executeDiagnostic.PostInvoke') && 'customDataValidation'.equals(input.get('diagnosticName')))
        {

            Map<String, Object> result = new Map<String, Object>();
            result.put('validationType', 'customDataValidation');

            boolean error = true;

            // perform diagnostic here.

            if(error)
            {
                result.put('validationMessage', '<Add validation message here>');
                result.put('howToFix', '<Mention steps on how to fix the issue.>');
                result.put('records', '<Mention record name or ids for which issue happens>');
            }
            output.put('result', result);
        }

        return true;
    }
}

In the Vlocity CMT Administration UI, diagnostic details are displayed as follows.

Sample Output:

Diagnostic Details