Using trim mode with the Winter ‘21 release

To use the trim mode feature with the Winter ‘21 release, you must create a class using the sample code below as a guide, create the interface, and create the interface implementation, as shown in the steps below:

  1. Create a CustomResultToXli class as shown in the example below:

    1// The following is sample code
    2global inherited sharing class CustomResultToXli implements vlocity_cmt.VlocityOpenInterface
    3{
    4    private static Set<String> fieldsToUpdate = new Set<String>{
    5        'vlocity_cmt__LineNumber__c'
    6    };
    7    private vlocity_cmt.VOIInvoker invoker = vlocity_cmt.VOIInvoker.getInstance();
    8    private vlocity_cmt.VlocityOpenInterface defaultResultToXli = (vlocity_cmt.VlocityOpenInterface)invoker.invoke('DefaultResultToXLIImplementation', 'debugCreate', null, null, null);
    9    // private VOIInvoker invoker = VOIInvoker.getInstance();// private VlocityOpenInterface defaultResultToXli = (VlocityOpenInterface)invoker.invoke('DefaultResultToXLIImplementation', 'debugCreate', null, null, null);public static void iterateJsonResult(Map<String, Object> jsonResult)
    10    {
    11        List<Object> jsonRecords = (List<Object>)jsonResult.get('records');
    12        for(Object jsonRecordObject : jsonRecords)
    13        {
    14            Map<String, Object> jsonRecord = (Map<String, Object>)jsonRecordObject;
    15            iterateJsonRecord(jsonRecord);
    16        }
    17    }
    18
    19    public static void iterateJsonRecord(Map<String, Object> jsonRecord)
    20    {
    21        for(String key :  fieldsToUpdate)
    22        {
    23            if(jsonRecord.get(key) == null || (jsonRecord.get(key) instanceOf Map<String,Object>))
    24            {
    25                continue;
    26            }
    27
    28            Map<String, Object> objMap = new Map<String,Object> {
    29                'value' => jsonRecord.get(key)
    30            };
    31            jsonRecord.put(key, objMap);
    32        }
    33
    34        if(jsonRecord.get('vlocity_cmt__PricingLogData__c') != null && jsonRecord.get('pricingLogValue') == null)
    35        {
    36            String logData = (String)jsonRecord.get('vlocity_cmt__PricingLogData__c');
    37            Map<String, Object> logDataMap = (Map<String, Object>)JSON.deserializeUntyped(logData);
    38            jsonRecord.put('vlocity_cmt__PricingLogData__c', logDataMap);
    39        }
    40
    41        Map<String, Object> productGroupsMap = (Map<String, Object>)jsonRecord.get('productGroups');
    42        if(productGroupsMap != null)
    43        {
    44            List<Object> productGroups = (List<Object>)productGroupsMap.get('records');
    45            for(Object productGroupObject : productGroups)
    46            {
    47                Map<String, Object> productGroup = (Map<String, Object>)productGroupObject;
    48                iterateJsonRecord(productGroup);
    49            }
    50        }
    51
    52        Map<String, Object> lineItemsMap = (Map<String, Object>)jsonRecord.get('lineItems');
    53        if(lineItemsMap != null)
    54        {
    55            List<Object> lineItems = (List<Object>)lineItemsMap.get('records');
    56            for(Object lineItemObject : lineItems)
    57            {
    58                Map<String, Object> lineItem = (Map<String, Object>)lineItemObject;
    59                iterateJsonRecord(lineItem);
    60            }
    61        }
    62
    63    }
    64
    65    global Boolean invokeMethod(String methodName, Map<String, Object> inputMap, Map<String, Object> outputMap,
    66                                Map<String, Object> options)
    67    {
    68        System.debug('****methodName**** ::: ' + methodName);
    69
    70        if (methodName.equalsIgnoreCase('generateXLIFromResult'))
    71        {
    72            Object result = inputMap.get('result');
    73            System.debug('****before**** ::: ' + JSON.serialize(result));
    74            Map<String, Object> resultMap;
    75            if(result instanceof String)
    76            {
    77                resultMap = (Map<String, Object>)JSON.deserializeUntyped((String)result);
    78                inputMap.put('result', resultMap);
    79            }
    80            else
    81            {
    82                resultMap = (Map<String, Object>)result;
    83            }
    84            iterateJsonResult(resultMap);
    85            System.debug('****after**** ::: ' + JSON.serialize(resultMap));
    86        }
    87
    88        //invoke actual method
    89        defaultResultToXli.invokeMethod(methodName, inputMap, outputMap, options);
    90        return true;
    91    }
    92}
  2. Create a ResultToXLI interface with active Implementation as CustomResultToXli.

    1. From the home screen, click the Interface Implementations tab and click New.

    2. Enter the following name and implementation class:

      • Interface Name: ResultToXli

      • Active Implementation Class: CustomResultToXli

      • Description: Enter a helpful description.

    3. Click Save.

    4. Click New Interface Implementation Detail.

    5. Enter the required information:

      • Available Implementation: CustomResultToXli

      • Interface Name: ResultToXli

      • Active: Checked