--- title: "SublineValidator" slug: "sublinevalidator" updated: 2023-06-27T17:31:15Z published: 2023-06-27T17:31:15Z canonical: "docs.zilliant.com/sublinevalidator" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.zilliant.com/llms.txt > Use this file to discover all available pages before exploring further. # Subline Validator Class Use this hook to identify data combinations between parent fields and their subline fields that are not valid. This hook is invoked in the **onChange** event in any field on any subline in the **Edit Lines** modal. The results of the hook identify validation errors. If errors exist, the hook prevents the user from saving the current state of sublines in the **Edit Lines** modal. ## Apex hook class - It must implement the **zpl.SublineValidatorConfigurer** interface. - It must have a global access modifier. - You must specify the Apex hook class name in the **Subline Validator Class** field of the **Product Selector Configuration** that is mapped to the **Line Items** component to be affected by the hook. ## Interface definition ``` /** * Interface for a hook class used to validate sublines. * * @param sublines the sublines that have been edited. * @return a Map were key is subline Id and value is Map where key is field api name and value * is error that will be displayed. */ global interface SublineValidator { Map> validateSublines(List sublines); } ``` ## Example of the class implementation ``` global class TestSublineValidator implements zpl.SublineValidator { global Map> validateSublines(List contractSublines) { Map> results = new Map>(); String errorMessage = 'Value isnt acceptable'; String errorMessage2 = 'Value should be <= 100'; for (SObject subline : contractSublines) { if ((Boolean)subline.get('zplpack1k__IsActive__c') ) { if ((Double)((zplpack1k__ContractSubline__c) subline).get('Number__c') == 25.0) { results.put(subline.Id, new Map{'Number__c' => errorMessage}); } else if ((Double)((zplpack1k__ContractSubline__c) subline).get('Number__c') == 30.0) { results.put(subline.Id, new Map{'Number__c' => errorMessage}); } if ((Double)((zplpack1k__ContractSubline__c) subline).get('Currency__c') > 100.0) { results.put(subline.Id, new Map{'Currency__c' => errorMessage2}); } } } return results; } } ``` ## Additional sample code ``` global with sharing class ValidationHook implements SublineValidator { global Map> validateSublines(List sublines) { Map> errors = new Map>(); for (SObject subline : sublines) { //here you can write any statement for each subline Map errorByField = new Map(); if (subline.get('zpl__ups_Guidance__c') < 10) //in this case if guidance is less than 10 then error message will appear for it { errorByField.put('zpl__ups_Guidance__c', 'error on Guidance'); errorByField.put('zpl__relatedGuidanceField__c', 'error for related field');//also here you can add validation for another field if this condition not suitable for it. } // so, after execution of this block, two error will appear for zpl__ups_Guidance__c - 'error on Guidance' and // for zpl__relatedGuidanceField__c - 'error for related field' if (subline.get('zpl__someTextField__c') == '') { errorByField.put('zpl__someTextField__c', 'this field cannot be empty'); }//this block add validation for zpl__someTextField__c that it cannot be empty errors.put(String.valueOf(subline.Id), errorByField); } return errors; } } ```