function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Meenu krishnaMeenu krishna 

how to write test class for the following code?

global with sharing class PriceAdjustmentHookImpl implements vlocity_cmt.VlocityOpenInterface
{
    global Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options)  
    {
        try
        {
            System.debug('____ PriceAdjustmentHookImpl' + methodName);
            
            if (methodName.equalsIgnoreCase('calculate.PreInvoke'))
            {
                system.debug('invoked pre');
                List<OrderItem> itemList = (List<OrderItem>)vlocity_cmt.PricingPlanService.getFromPricingContext('LineItemList'); 
                system.debug(LoggingLevel.ERROR, 'itemList' + itemList);
                String  itemList1= '';//(String)itemMap.get('vlocity_cmt__Action__c');
                
                if(itemList[0].vlocity_cmt__Action__c=='Existing')  
                {   
                  System.debug('--- calculate.PreInvoke input: ' + JSON.serialize(input));
                  Map<String, Object> pricingVariableCodeToValueMap = (Map<String, Object>)input.get('pricingVariableMap');
                  Decimal REC_MNTH_STD_PRC = (Decimal)pricingVariableCodeToValueMap.get('REC_MNTH_STD_PRC');
                  system.debug('REC_MNTH_STD_PRC'+REC_MNTH_STD_PRC);
                  pricingVariableCodeToValueMap.put('REC_MNTH_STD_PRC', 0.0); 
               }
            else if (methodName.equalsIgnoreCase('calculate.PostInvoke'))
            {                
              system.debug('invoked post');
 
            }
           }
            return true;
        }
        catch (Exception ex)
        {
            System.debug('--- Exception: ' + ex.getMessage());
            System.debug('--- Stack Trace: ' + ex.getStackTraceString());
            throw ex;
        }
    }
}
Deepak GerianiDeepak Geriani
Hi,
Please refer to the link (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm ) on how to write the test and The Testing Best Practices (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm)

If this info has helped you to resolve your issue please mark this answer as resolved.
Thanks