This Apex hook adds filter conditions to the query that retrieves lines to be shown in an instance of the Line Items component.
The hook filters out records before a line list is presented to a user in the Line List view.
Apex hook class
- It must implement the ScopedLineItemsFilterer interface.
- It must have a global access modifier.
- You must specify the Apex hook class name in the Line Items Filterer Class Name field of the Product Selector Configuration.
Interface definition
/**
* Interface for a hook class that encapsulates custom Contract Line Items pre-entry fields
* filtering logic on Line-Items page. This version of the interface extends
* LineItemsFilterer to add the option to include scoping restrictions.
* To ignore scope, use LineItemsFilterer directly.
*/
global interface ScopedLineItemsFilterer extends LineItemsFilterer
{
/**
* @param headerRecordId the ID of current Header object record (ID of Contract or Price Lookup record)
* @param scope map of system-defined values by which to constrain the available records
* KEY: name of the scoping element, VALUE: value of the scoping element
*
* @returns a condition that should be used on selecting ContractLineItems.
*/
zal.Condition getScopedFilterCondition(Id headerRecordId, Map<String, Object> scope);
}
Example of the class implementation
public with sharing class SimpleScopedLineItemsFilterer implements zpl.ScopedLineItemsFilterer
{
public zal.Condition getScopedFilterCondition(Id headerRecordId, Map<String, Object> scope)
{
String var = (String)scope.keySet().iterator().next();
return new zal.FieldCondition(Schema.SObjectType.zpl__ContractLineItem__c.fields.zpl__LevelValue__c.getName(),
zal.Operator.EQUALS, scope.get(var));
}
public zal.Condition getFilterCondition(Id headerRecordId) {
return null;
}
}