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

Displaying records in VF page
Hi All,
I am trying to display the Account records on Visual Force Page where Phone and fax fields values are equal.
I have written a Controller and design a VF page. But when I am clicking on "Display records" Button then I am getting below error.
Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!display}' in component <apex:commandButton> in page displayrecords: Class.DispalyMatchingRecords.display: line 9, column 1
Class.DispalyMatchingRecords.display: line 9, column 1
I tried to debug this, Actually while adding the value in "acc" list its throwing the error.
Could anyone help me out here. Actually I am not having much knowledge of VF pages so not sure where I am doing wrong.
VF Page:-
<apex:page controller="DispalyMatchingRecords" >
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value= "{!a.Id}"/>
<apex:column value= "{!a.Name}"/>
</apex:pageBlockTable>
<apex:commandButton value="Display Records" action="{!display}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:-
public class DispalyMatchingRecords {
public List<Account> acc {get;set;}
public void display(){
List<Account> ac =[Select Id, Name, Phone,Fax from Account];
for(Account a: ac){
if(a.Phone != null && a.Fax != null){
if(a.Phone == a.Fax){
acc.add(a);
}
}
}
}
}
I am trying to display the Account records on Visual Force Page where Phone and fax fields values are equal.
I have written a Controller and design a VF page. But when I am clicking on "Display records" Button then I am getting below error.
Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!display}' in component <apex:commandButton> in page displayrecords: Class.DispalyMatchingRecords.display: line 9, column 1
Class.DispalyMatchingRecords.display: line 9, column 1
I tried to debug this, Actually while adding the value in "acc" list its throwing the error.
Could anyone help me out here. Actually I am not having much knowledge of VF pages so not sure where I am doing wrong.
VF Page:-
<apex:page controller="DispalyMatchingRecords" >
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value= "{!a.Id}"/>
<apex:column value= "{!a.Name}"/>
</apex:pageBlockTable>
<apex:commandButton value="Display Records" action="{!display}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:-
public class DispalyMatchingRecords {
public List<Account> acc {get;set;}
public void display(){
List<Account> ac =[Select Id, Name, Phone,Fax from Account];
for(Account a: ac){
if(a.Phone != null && a.Fax != null){
if(a.Phone == a.Fax){
acc.add(a);
}
}
}
}
}
sfdcMonkey.com
All Answers
sfdcMonkey.com
Try this
Thanks :)
Its worked. that was a silly mistake done by me.
Thanks a lot .
Regards,
Anuj