I have created a simple VF search page which returns a list of email addresses but getting NULL pointer exception in line 14 when I execute the search in VF page.
Seeing that line 14 is the line which has NULL, I added a debug before that which return the ID in a.Merchant_Profile__r.Profile_Account_Name__c field. Is there a reason why it's NULL when trying to add this field into the Set acc?
Line 13: system.debug(a.Merchant_Profile__r.Profile_Account_Name__c); Line 14: acc.add(a.Merchant_Profile__r.Profile_Account_Name__c);
Cheers, Chris
**My controller class:**
public with sharing class OutageContacts {
public list <contact> con {get;set;}
public Set<ID> acc {get;set;}
public string searchstring {get;set;}
public string contactlist {get;set;}
public OutageContacts(ApexPages.StandardController controller) {
}
public void search(){
searchstring = '%'+searchstring+'%';
system.debug(searchstring);
for(Acquirer_Link__c a : [SELECT Merchant_Profile__r.Profile_Account_Name__c, Merchant_Profile__r.Merchant_ID__c FROM Acquirer_Link__c WHERE Acquirer_Name__c LIKE :searchstring])
{
system.debug(a.Merchant_Profile__r.Profile_Account_Name__c);
acc.add(a.Merchant_Profile__r.Profile_Account_Name__c);
}
string contactlist='SELECT Account.name, Account.Line_Of_Business__c, email FROM Contact WHERE AccountID IN :acc';
con = Database.query(contactlist);
}
public void clear(){
con.clear();
}
}
**The VF page:**
<apex:page standardController="contact" extensions="OutageContacts " sidebar="false">
<apex:form >
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search records" action="{!search}"/>
<apex:commandButton value="Clear records" action="{!search}"/>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!con}" var="c">
<apex:column >
<apex:outputlink value="https://test.salesforce.com/{!c.id}">{!c.Name}</apex:outputlink>
</apex:column>
<apex:column value="{!c.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>