Conga Product Documentation

Welcome to the new doc site. Some of your old bookmarks will no longer work. Please use the search bar to find your desired topic.

Show Page Sections

Asset Line Item Validation Callback Class

This callback interface allows you to validate all the asset-based amendments performed for a wallet asset on the cart page.

To add the custom class

  1. Go to Setup > App Setup > Develop > Apex Classes.
  2. Click New.
  3. Enter the sample callback class code.
  4. Click Save.
    Warning: In order to implement the interface, prefix it with Apttus_Billing.CustomClass.<Interface Name>

Code Sample

The sample callback class performs the following validations to prevent the user from removing funds more than the available balance:

  • Discount % should be between 1- 100 %
  • Discount amount cannot be more than 100%
  • Discount amount cannot be more than the available amount
  • Price Override adjustment amount cannot be more than the available balance
  • Base Price Override adjustment amount cannot be more than the available balance
Note: This is just a sample callback class. You may change the code per your requirements.
global interface IValidationCallback2 {
	global Apttus_Config2.CustomClass.ValidationResult validateCart(Apttus_Config2.ProductConfiguration configuration) {
	}
	global Apttus_Config2.CustomClass.ValidationResult validateAssetItems(Apttus_Config2.ProductConfiguration cart, List<Apttus_Config2__TempRenew__c> assetItems) {
     
	}    
   
    global Apttus_Config2.CustomClass.ValidationResult validateRampLineItems(Apttus_Config2.ProductConfiguration cart, List<Apttus_Config2.LineItem> rampLineItems) {
        
    }

    private static List<Apttus_Config2__LineItem__C> getLineItems(List<Apttus_Config2.LineItem> allLines) {
       
    }
}
global with sharing class AssetlineItemValidationCallBack implements Apttus_Config2.CustomClass.IValidationCallback2 {
   
    // system properties
    public static final String PROP_SYSTEM_PROPERTIES = 'System Properties';

    //Error Message display on cart
    public static final String DISCOUNT_VALIDATION_ERROR_MESSAGE = 'You cannot remove funds more than the available balance. Please enter a discount percentage between 1 and 100';
    public static final String AMOUNT_VALIDATION_ERROR_MESSAGE = 'You cannot remove funds more than the available balance. Please enter an amount less than (or) equal to the available balance';


    global Apttus_Config2.CustomClass.ValidationResult validateCart(Apttus_Config2.ProductConfiguration configuration) {
        Apttus_Config2.CustomClass.ValidationResult result = new Apttus_Config2.CustomClass.ValidationResult(true);
        
        Boolean flag = false;
        String errorMessage;
        
        //WalletFlow Field Value from Billing System Properties
        String walletFlowname;
        
        try {
            
            Apttus_Billing__BillingSystemProperties__c prop = Apttus_Billing__BillingSystemProperties__c.getInstance(PROP_SYSTEM_PROPERTIES);
            walletFlowname = prop.WalletFlow__c;
            
            List<Apttus_Config2__TempObject__c> tempData = [SELECT Id,Apttus_Config2__Data__c 
                                                                FROM Apttus_Config2__TempObject__c 
                                                                WHERE Apttus_Config2__ConfigurationId__c = :configuration.getConfigSO().Id 
                                                                LIMIT 1];
            if(tempData != null && !tempData.isEmpty()) {
                String xml = tempData[0].Apttus_Config2__Data__c;
                Dom.Document doc = new Dom.Document();
                doc.load(xml);
                Dom.XMLNode xroot = doc.getRootElement();
                List<Dom.XmlNode> param = new List<Dom.XmlNode>();
                param = xroot.getChildElement('Params', null).getChildElements();
                for(Dom.XmlNode child : param) {
                    if(child.getChildElement('Value',null).getText() == walletFlowname) {
                        flag=true;
                        break;
                    }
                }
            }
            
            if(flag == false) {
                return result;
            }
            
            if(flag == true) {
                List<Apttus_Config2.LineItem> allLines = configuration.getLineItems();
                if (allLines.size() == 0) {
                    return result;
                }
                
                list<Apttus_Config2__LineItem__c> lineItemList = getLineItems(allLines);

                for(Apttus_Config2__LineItem__c lineItem : lineItemList) {

                    if((lineItem.Apttus_Config2__AdjustmentType__c == '% Discount' || lineItem.Apttus_Config2__AdjustmentType__c == '% Discount Off List')
                        && lineItem.Apttus_Config2__AdjustmentAmount__c > 100) {
                        errorMessage = DISCOUNT_VALIDATION_ERROR_MESSAGE;
                    }

                    if((lineItem.Apttus_Config2__AdjustmentType__c == 'Discount Amount' || lineItem.Apttus_Config2__AdjustmentType__c == 'Price Override' || lineItem.Apttus_Config2__AdjustmentType__c == 'Base Price Override')
                        && lineItem.Apttus_Config2__AdjustmentAmount__c > lineItem.AvailableBalance__c) {
                        errorMessage = AMOUNT_VALIDATION_ERROR_MESSAGE;
                    }
                }

                if(!String.isEmpty(errorMessage)) {
                    result.isSuccess = false;
                    result.Messages.add(new apexpages.Message(Apexpages.Severity.Error, '' + errorMessage));
                }
            }  
        } 
        catch (Exception ex) {
            errorMessage = 'Validation callback Exception: ' + ex.getMessage();
            System.debug('Validation callback Exception: ' + ex.getMessage());
            result.isSuccess = false;
            result.Messages.add(new apexpages.Message(Apexpages.Severity.Error, '' + errorMessage));
        }   
        
        return result;
    }
    
    global Apttus_Config2.CustomClass.ValidationResult validateAssetItems(Apttus_Config2.ProductConfiguration cart, List<Apttus_Config2__TempRenew__c> assetItems) {
        Apttus_Config2.CustomClass.ValidationResult result;
        return result;
    }    
   
    global Apttus_Config2.CustomClass.ValidationResult validateRampLineItems(Apttus_Config2.ProductConfiguration cart, List<Apttus_Config2.LineItem> rampLineItems) {
        Apttus_Config2.CustomClass.ValidationResult result;
        return result;
    }

    private static List<Apttus_Config2__LineItem__C> getLineItems(List<Apttus_Config2.LineItem> allLines) {
        List<Apttus_Config2__LineItem__C> lineItems = new List<Apttus_Config2__LineItem__C>();
        for (Apttus_Config2.LineItem lineItemMO : allLines) {
            lineItems.add(lineItemMO.getLineItemSO());
        }
        return lineItems;
    }
}

To add the name of custom callback class, go to Setup > App Setup > Develop > Custom Settings and click Manage beside Config Custom Classes. Click Edit for System Properties and enter the name of your custom callback class in Validation Callback Class.