Filter Field Post Processor
  • 27 Jun 2023
  • 1 Minute to read
  • Dark
    Light

Filter Field Post Processor

  • Dark
    Light

Article summary

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;
    }
}


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.