• Amita_Acc
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I'm attempting to created a VF page that takes a zip (or series of zips) and create a paginated list of related Accounts. I'm having issues retrieving the data, namely receiving the Attempt to de-reference a null object error.

 

Here's my VF:

 

<apex:form >
	<apex:pageBlock title="Search by Zip">
		<apex:inputText value="{!zips}" />
		<apex:commandButton value="Search" action="{!find}" />
	</apex:pageBlock>

	<apex:pageBlock title="Nearby Company/Branch" rendered="{!zips != null}">
		<apex:pageBlockTable value="{!accounts}" var="acct" id="accountTable">
			<apex:column headerValue="Company/Branch">
				<apex:outputLink value="/{!acct.Id}" target="_top">{!acct.Name}</apex:outputLink>
			</apex:column>
			<apex:column headerValue="Address" colspan="2">
				<apex:outputText >{!acct.BillingStreet}, {!acct.BillingCity}, {!acct.BillingState}, {!acct.BillingPostalCode}</apex:outputText>
			</apex:column>
			<apex:column >
				<apex:outputLink value="http://maps.google.com/maps?f=d&source=s_d&saddr=&daddr={!acct.BillingStreet},{!acct.BillingCity},{!acct.BillingState},{!acct.BillingPostalCode}" target="_blank">Get Directions</apex:outputLink>
			</apex:column>
		</apex:pageBlockTable>
	</apex:pageBlock>

	<apex:panelGrid columns="4" style="margin-bottom: 25px;" rendered="{!zips != null}">
		<apex:commandLink action="{!first}" rendered="{!(pages > 1) && (hasPrevious)}">First</apex:commandLink>
		<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandLink>
		<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandLink>
		<apex:commandLink action="{!last}" rendered="{!(pages > 1) && (hasNext)}">Last</apex:commandLink>
	</apex:panelGrid>
</apex:form>

 

Here's my controller class:

 

 

public with sharing class zipMap {
	
	public String zips { get; set; }
	
	public List<String> zList { get; set; }
	
	public ApexPages.StandardSetController accts { get; set; }
	
	public PageReference find() {

		zList = zips.split(',');

		String query = 'SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode FROM Account WHERE BillingPostalCode =: ' + zList + ' ORDER BY BillingPostalCode, Name';
		
		accts = new ApexPages.StandardSetController(Database.getQueryLocator(query));
		accts.setPageSize(2);
		
		return null;
	
	}
	
	public List<Account> getAccounts() {
		
		return (List<Account>) accts.getRecords();
		
	}
	
	public Boolean hasNext {
		
		get {
			
			return accts.getHasNext();
			
		}
		
		set;
		
	}
	
	public Boolean hasPrevious {
		
		get {
			
			return accts.getHasPrevious();
			
		}
		
		set;
		
	}
	
	public Integer pageNumber {
		
		get {
			
			return accts.getPageNumber();
			
		}
		
		set;
		
	}

	public Integer pages {
		
		get {
		
			pages = accts.getResultSize()/accts.getPageSize();
			
			return pages;
			
		}
		
		set;
		
	}
	
	public void first() { accts.first(); }
	
	public void last() { accts.last(); }

	public void cancel() { accts.cancel(); }
		
	public PageReference previous() {
		
		Integer p = accts.getPageNumber();
		
		if(hasPrevious) {
		
			accts.setPageNumber(p-1);
		
		}
		
		return null;
		
	}
	
	public PageReference next() {
		
		Integer p = accts.getPageNumber();
		
		if(hasNext) {
		
			accts.setPageNumber(p+1);
		
		}
		
		return null;
		
	}

}

 

 

Can someone please help? Thanks

 

Adriel

  • September 09, 2010
  • Like
  • 0