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

Fetching Records
Hi my requirement is, i want to fetdch the recors from Account object based on the name enter in the VFpage, (when i enter the name ram in VFpage ,then total recordswith the Name ram have to be fetched ) for that i have written the belwo code, in this codewhen enter the name in the vfpage ima getting the error like bleow
"Attempt to de-reference a null object
Error is in expression '{!values}' in component <apex:commandButton> in page chennai: Class.chennai.values: line 18, column 1 "
andmy code is as follows,
vf code:
<apex:page controller="chennai">
<apex:form>
<apex:outputText>EnterName</apex:outputText>
<apex:inputField value="{!a.Name}"/>
<apex:commandButton value="Enter" action="{!values}" reRender="one"/>
<apex:pageBlock id="one">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!at}" var="b">
<apex:column value="{!b.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
Public class chennai
{
Public chennai()
{
List<Account> at=new List<Account>();
Account a=new Account();
}
Public List<Account> at{get;set;}
Public Account a{get;set;}
Public void values()
{
List<Account> at=[select Name from Account where Name=:a.Name];
}
}
Please suggest me
Regards,
siva.
"Attempt to de-reference a null object
Error is in expression '{!values}' in component <apex:commandButton> in page chennai: Class.chennai.values: line 18, column 1 "
andmy code is as follows,
vf code:
<apex:page controller="chennai">
<apex:form>
<apex:outputText>EnterName</apex:outputText>
<apex:inputField value="{!a.Name}"/>
<apex:commandButton value="Enter" action="{!values}" reRender="one"/>
<apex:pageBlock id="one">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!at}" var="b">
<apex:column value="{!b.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
Public class chennai
{
Public chennai()
{
List<Account> at=new List<Account>();
Account a=new Account();
}
Public List<Account> at{get;set;}
Public Account a{get;set;}
Public void values()
{
List<Account> at=[select Name from Account where Name=:a.Name];
}
}
Please suggest me
Regards,
siva.
That error occur due to null value.
What is {!a.name} in your VF page? to bind inputfield you can use controller variable which have {get; set;} property
or if you have standard variable then you can use Objectname.field name but in your case you are using custom controller so instead of {!a.name} use a string variable to hold account name.
and in your controller: also change in your values method:
All Answers
That error occur due to null value.
What is {!a.name} in your VF page? to bind inputfield you can use controller variable which have {get; set;} property
or if you have standard variable then you can use Objectname.field name but in your case you are using custom controller so instead of {!a.name} use a string variable to hold account name.
and in your controller: also change in your values method:
<apex:form >
<apex:outputText >EnterName</apex:outputText>
<apex:inputText value="{!searchTxt}" />
<apex:commandButton value="Enter" action="{!values}" reRender="one"/>
<apex:pageBlock id="one">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!at}" var="b">
<apex:column value="{!b.Name}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
===============================================================================
Public class chennai
{
public string searchTxt {get; set;}
public List<Account> at{get; set;}
Public void values()
{
if ( searchTxt != null && searchTxt!= '') {
system.debug('searchTxt '+searchTxt );
at=[SELECT Id,name,phone FROM Account WHERE Name LIKE: '%'+searchTxt+'%' ];
}
}
}
hope this code is helpfull.......