Skip to main content

Lookup Filter Plugin

Zuora

Lookup Filter Plugin

Quote Studio now allows you to add filter logic via plugin for custom lookup fields such as 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 

Procedure

To activate the Lookup Filter plugin:

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

clipboard_e6c8b7163d102e80fab81ddf81fc20423.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);
       
      
 }

}