Skip to main content

Lookup Filter Plugin

Zuora

Lookup Filter Plugin

Quote Studio provides the capability to apply filter logic using plugins for both managed packaged lookup fields and custom lookup fields established within the Quote Object, including fields like Bill to Contact, Sold to Contact, Opportunity, etc.

Use the ILookupFilter on the LookupFilterPlugin component to add filters into Lookup fields that are released with the CPX package. Ex, Sold To Contact, Bill to Contact, Opportunity, etc.

The plugin interface is defined as:

global zqu.LookupFilterPlugin.ILookupFilter

The plugin contains the following interface methods.

Return Type Method Input Parameters
zqu.LookupFilterPlugin.LookupFilter getFilter zqu.LookupFilterPlugin.FilterRequest 

zqu.LookupFilterPlugin.LookupFilter

All field names are case sensitive.

Field Description
objectName To add “And/or” conditions, the default consideration is an "AND" condition.

For example: (1 OR 2) AND 3

List<FilterField> filters Catalog of filters that will sort out records.

FilterField:
  • objectName - The object's name for which filtering is required.
  • fieldName - The name of the field within the object that needs to undergo filtering.
  • fieldValue - The value used for filtering.
  • OperatorThe operator condition.

Example Use Cases 

Example 1: Filter Contacts with a Type__C value equal to 'SoldTo'

filter.filters.add(new zqu.LookupFilterPlugin.FilterField('Contact','Type__c', 'SoldTo', zqu.LookupFilterPlugin.Operator.EQUAL));

Example 2: Filter Opportunities where the AccountId matches the accountId of the current Quote


string accountId = (string) request.sourceObject.get('zqu__Account__c');

filter.filters.add(new zqu.LookupFilterPlugin.FilterField('Opportunity', 'AccountId', accountId, zqu.LookupFilterPlugin.Operator.EQUAL));

zqu.LookupFilterPlugin.Operator

The following operators are supported:

  • EQUAL
  • NOT_EQUAL
  • GREATER_THAN
  • GREATER_OR_EQUAL
  • LESS_THAN
  • LESS_OR_EQUAL
  • CONTAINS
  • NOT_CONTAINS
  • START_WITH
  • INCLUDE_IN

zqu.LookupFilterPlugin.FilterRequest

All field names are case sensitive.

Field Description
filterCondition The name of the object for which the filter is invoked. Currently, it exclusively supports zqu__Quote__c, ensuring that it always returns zqu__Quote__c.
fieldName The name of the field for which the filter is invoked, such as zqu__SoldToContact__c, zqu__Opportunity__c, or any custom lookup field name.
sourceObject This field contains the values for which the filter is invoked. It can be utilized to obtain the necessary values for constructing the filter.

Example

Let's consider a scenario where you intend to filter Opportunities based on the current Quote's account. In this case, you retrieve the account ID using the source object.

string accountId = (string) sourceObject.get('zqu__Account__c');

Procedure

To activate the Lookup Filter plugin:

  1. Navigate to Zuora Config > Quote Studio Settings > Plugins.
  2. Switch the Lookup Filter Plugin toggle to Active, then add the class name of your custom plugin.

clipboard_ef32dc026ab47e70ffe954fb014f3f714.png

  1. Click Save.

Sample Code for Lookup Filter Plugin

The following is a code sample for the Lookup Filter Plugin.


/*
    Create new Picklist field "Type__c" into contact object to store
    "SoldTo" and "BillTo" type of contact.
    
    Object: Contact
    
    Field Name: Type__c
    
    PickList Value: SoldTo,BillTo
   
*/

    global with sharing class CustomLookupFilter implements
    zqu.LookupFilterPlugin.ILookupFilter {
    
     global zqu.LookupFilterPlugin.LookupFilter
     getFilter(zqu.LookupFilterPlugin.FilterRequest request) {
     
      zqu.LookupFilterPlugin.LookupFilter filter = new
      zqu.LookupFilterPlugin.LookupFilter();
      // Add Filter into Sold To Contact Field
      if (request.objectName == 'zqu__Quote__c' && request.fieldName ==
      'zqu__SoldToContact__c') {
       
      filter = getSoldToContactFilter(request);
      
  }
  
      // Add Filter into Bill To Contact Field
      else if (request.objectName == 'zqu__Quote__c' && request.fieldName ==
      'zqu__BillToContact__c') {
      filter = getBillToContactFilter(request);
      
  }
  
      // Add Filter into Opportunity Field
      else if (request.objectName == 'zqu__Quote__c' && request.fieldName ==
      'zqu__Opportunity__c') {
      filter = getOpportunityFilter(request);
      
  }
  
  return filter;
  
 }
 
     private zqu.LookupFilterPlugin.LookupFilter
     getSoldToContactFilter(zqu.LookupFilterPlugin.FilterRequest request) {
     
     //Filter contact records where Type__c equals to "SoldTo"
     
     zqu.LookupFilterPlugin.LookupFilter filter = new
     zqu.LookupFilterPlugin.LookupFilter();
     
     filter.filters = new List<zqu.LookupFilterPlugin.FilterField>();
     
     filter.filters.add(new zqu.LookupFilterPlugin.FilterField('Contact',
     'Type__c', 'SoldTo', zqu.LookupFilterPlugin.Operator.EQUAL));
     
     return filter;
     
 }
 
     private zqu.LookupFilterPlugin.LookupFilter
     getBillToContactFilter(zqu.LookupFilterPlugin.FilterRequest request) {
     
    //Filter contact records where Type__c equals to "BillTo"
    
    zqu.LookupFilterPlugin.LookupFilter filter = new
    zqu.LookupFilterPlugin.LookupFilter();
    
    filter.filters = new List<zqu.LookupFilterPlugin.FilterField>();
    
    filter.filters.add(new zqu.LookupFilterPlugin.FilterField('Contact',
    'Type__c', 'BillTo', zqu.LookupFilterPlugin.Operator.EQUAL));
    
    return filter;
  
 }
 
     private zqu.LookupFilterPlugin.LookupFilter
     getOpportunityFilter(zqu.LookupFilterPlugin.FilterRequest request) {
     
    //Filter Opportunity records where Opportunity account is match with
    current quotes account.
    
    zqu.LookupFilterPlugin.LookupFilter filter = new
    zqu.LookupFilterPlugin.LookupFilter();
    
    string accountId = (string)
    request.sourceObject.get('zqu__Account__c');
    
    filter.filters = new List<zqu.LookupFilterPlugin.FilterField>();
    
    filter.filters.add(new
    zqu.LookupFilterPlugin.FilterField('Opportunity', 'AccountId', accountId,
    zqu.LookupFilterPlugin.Operator.EQUAL));
    
    return filter;
    
 }
 
     //Use LookupFilter.filterCondition field to add “And/or” conditions,ex.
     (1 or 2) and 3, by default it will be considered as an "And" condition.
     
}

Test Class for Lookup Filter Plugin

The following is a APEX test class code sample for Lookup Filter Plugin. You can use the test class to achieve code coverage on the plugin in Salesforce.


@IsTest(SeeAllData=false)
public with sharing class CustomLookupFilterTest{

@IsTest

public static void testGetFilter() {

     zqu.LookupFilterPlugin.FilterRequest request =new 
     zqu.LookupFilterPlugin.FilterRequest();
     
     request.objectName='zqu__Quote__c';
     
     request.fieldName='zqu__SoldToContact__c';
     
     request.sourceObject=new zqu__Quote__c();
       
     CustomLookupFilter pluginObj=new CustomLookupFilter();
     
     zqu.LookupFilterPlugin.LookupFilter 
     lookupFilter=pluginObj.getFilter(request);
       
     System.assertEquals(1,lookupFilter.filters.size());
     
     System.assertEquals('Type__c',lookupFilter.filters[0].fieldName);
     
     System.assertEquals('SoldTo',lookupFilter.filters[0].fieldValue);
       
     request.fieldName='zqu__BillToContact__c';
     
     lookupFilter=pluginObj.getFilter(request);
     
     System.assertEquals(1,lookupFilter.filters.size());
     
     System.assertEquals('Type__c',lookupFilter.filters[0].fieldName);
     
     System.assertEquals('BillTo',lookupFilter.filters[0].fieldValue);
     
       
     request.fieldName='zqu__Opportunity__c';
     
     lookupFilter=pluginObj.getFilter(request);
     
     System.assertEquals(1,lookupFilter.filters.size());
     
     System.assertEquals('AccountId',lookupFilter.filters[0].fieldName);
       
      
 }

}