You need to sign in to do that
Don't have an account?

Dynamic queries from booleans - Advice?
I have an existing search (contacts) page, but wanted to add booleans to filter out results. So, if boolean A is ticked, i only want accounts with a picklist value of "A" and if B is ticked, only accounts with picklist values of B. If both ticked, both sets.
With the help of a peer, I've gotten a little further on this - but I'm wondering why this throws the following error:
caused by: System.NullPointerException: Attempt to de-reference a null object
External entry point
Class.ProposalExtension.vendorSearch: line 325, column 1
Visualforce page snippet: Extensions = ProposalExtension
<apex:pageBlockSection title="Vendor Panel Options"> <apex:pageBlockSectionItem > <apex:outputLabel for="civasPanel" value="Enable Shared Panel"/> <apex:inputCheckbox id="civasPanel" value="{!includeA}"/> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel for="civasPanel2" value="Enable Private Panel"/> <apex:inputCheckbox id="civasPanel2" value="{!includeB}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection>
ProposalExtension line 325 highlighted below
public with sharing class ProposalExtension { public Boolean includeA {get; set;} //Experimenting with vPanel toggle public Boolean includeB {get; set;} private final Proposal__c p; public ProposalExtension(ApexPages.StandardController pCon) { this.p = (Proposal__c)pCon.getRecord(); } //Used to create lookup fields for Vendor Search Contact con; public Contact getCon() { if(con == null) con = new Contact(); con.RecordTypeId = '012A00000007dJ4'; //Set the Record Type to "Vendor" return con; } //Create a Wrapper/Container class for Vendors to be used in implementing a checkbox list public class checkedVendor{ public Contact ven {get;set;} public Boolean checked {get;set;} //Constructor method for checkedVendors class public checkedVendor(Contact v){ ven = v; checked = false; } } //Create a list of new wrapper class/container object checkedVendors public List<checkedVendor> vendorList {get;set;} //Create a PageReference to execute the Vendor Search public PageReference vendorSearch() { vendorList = new List<checkedVendor>(); List<String> picklistVals = new List<String>(); if(includeA) { picklistVals.add('Shared'); } if(includeB) { picklistVals.add('Private'); } if(radius == 0) { radius = 1; } //Creates an instance of Vendor Search VendorSearch vs = new VendorSearch(); try { //Query for Vendors within the selected Radius, matching Type, and Primary Specialty //LINE 325 for(Contact v : vs.searchVendors(con.Primary_County__c, radius, con.Type__c, con.Primary_Specialty__c, picklistVals)){ //Add a checkbox to each Vendor that is returned in the search vendorList.add(new checkedVendor(v)); } } catch(QueryException q) { } return null; } }
VendorSearch, i've highlighted the problem line.
public with sharing class VendorSearch { public Id countyId; //County to be used as starting point public Integer radius = 1; //Desired radius in miles from starting point public String vType; //Desired Vendor Type public String specialty; //Desired Vendor Specialty public String noSpecialty; //No Vendor Specialty place holder public List<String> picklistVals; //experimenting with panel pickval public VendorSearch() { } //Create a list of Contacts to hold available Vendors public List<Contact> searchVendors(Id startingCounty, Integer searchRadius, String vendorType, String vendorSpecialty, List <String> pVals) { countyId = startingCounty; radius = searchRadius; vType = vendorType; specialty = vendorSpecialty; noSpecialty = vendorSpecialty; pVals = picklistVals; if(noSpecialty == NULL){ noSpecialty = '%'; } List<Contact> vendors; try { //Get the County Ids from the map and create Set for the search query Set<Id> radiusSet = radiusMap().keySet(); //Query for Vendors within the selected Radius, matching Type, and Primary Specialty vendors = (List<Contact>)[SELECT Id, Name, Account.Name, Account.Revos_Status__c, Designation__c, Phone, Email, Primary_County__c, Type__c, Status__c, Status_Sort__c, Overall_Rating__c, RecordTypeId, Minority_Status__c FROM Contact WHERE Primary_County__c IN :radiusSet //PROBLEM AND Account.Revos_Status__c IN :pVals //Trying to filter out results from booleans on visualforce page AND Type__c INCLUDES (:vType) AND (Primary_Specialty__c LIKE :noSpecialty OR Primary_Specialty__c LIKE :specialty) ORDER BY Status_Sort__c ASC, Overall_Rating__c DESC]; } catch(QueryException q) { } return vendors; } }
Found it.
Sigh.
vendorSearch:
needs to be:
All Answers
Updated after following some advice. Tried to refactor existing code with this psuedo-code.
Anyone?
Found it.
Sigh.
vendorSearch:
needs to be: