- 27 Jun 2023
- 1 Minute to read
- Print
- DarkLight
Filter Field Post Processor
- Updated on 27 Jun 2023
- 1 Minute to read
- Print
- DarkLight
This Apex hook can filter line items in the Line Items list view based on the values that a user enters in one or more Post Processable Filter Fields.
This feature adds the ability to configure a more complex filtering in the Line Items and Workspace lists, when the value does not explicitly exist in the field of the line object.
Users can set up one or more filter fields (Post-Processable Filter Field) on the Line Items list that are not for directly querying the lines displayed. The user then populates these fields and the system sends the user-entered values to the hook. The hook has logic to display only the records based on the values the user enters in the Post-Processable Filter field.
The hook occurs after a user enters a value in each Post-Processable Filter Field.
Apex hook class
- It must implement the zpl.FilterFieldPostProcessor interface.
- It must have a global access modifier.
- You must specify the Apex hook class name in the Post-Processor Class field on the record of the SObject Post-Processable Filter Field for which the class is written.
Interface definition
global interface FilterFieldPostProcessor
{
zal.Condition getFilterCondition(zpl__PostProcessableFilterField__c filterField, Object value);
}
Example of the class implementation
global with sharing class SimpleFilterFieldPostProcessor implements zpl.FilterFieldPostProcessor
{
global zal.Condition getFilterCondition(zpl__PostProcessableFilterField__c filterField, Object value)
{
// value is Id of the 'voser_pl__Package__c' object record that user selected
zal.AndCondition condition = new zal.AndCondition();
if (filterField.voser_pl__SObjectTypeName__c == 'voser_pl__Package__c')
{
// I have 'voser_pl__Package__c' object that has many-to-many relationship with 'Product2' object,
// using 'voser_pl__ProductPackageAssociation__c' intersection object.
// 'voser_pl__ProductPackageAssociation__c' has 2 Lookup fields to 'Product2' and 'voser_pl__Package__c' objects,
// called 'voser_pl__Product__c' and 'voser_pl__Package__c'
String query = new zal.SoqlBuilder()
.selectx('voser_pl__Product__c')
.fromx('voser_pl__ProductPackageAssociation__c')
.wherex(new zal.FieldCondition('voser_pl__Package__c', zal.Operator.EQUALS, value))
.toSoql();
Set<String> productIds = new Set<String>();
for (SObject association : Database.query(query))
{
productIds.add(String.valueOf(association.get('voser_pl__Product__c')));
}
// making condition that 'zpl__Product__c' field on a line object should have a value from a list of that product ids
condition.add(new zal.SetCondition('zpl__Product__c', zal.Operator.INX, new List<String>(productIds)));
}
return condition;
}
}