You need to sign in to do that
Don't have an account?
Saaku
Fetch the record from custom object Customer__c by name and it should display relevant fields
Hi folks!
my apec class is
public class fetch {
public String accountname{set;get;}
public string destquery{set;get;}
public List<customer__c> cust{set;get;}
public fetch(){
string accountname;
cust=new List<customer__c>();
}
public void show(){
destquery='select Balance__c,City__c,State__c from Customer__c where name=\'' +accountname+'\'';
}
}
My vf page is
<apex:page controller="fetch">
<apex:form >
<apex:pageBlock >
<apex:outputLabel value="Name" /><apex:inputText >{!accountname}</apex:inputText>
<apex:commandButton value="Ok" action="{!show}"/>
</apex:pageBlock>
<apex:pageBlock >
<!-- <apex:pageBlockTable value="{!destquery}" var="a">
<apex:column value="{!a.Balance__c}" />
<apex:column value="{!a.City__c}" />
<apex:column value="{!a.State__c}" />
</apex:pageBlockTable> -->
{!accountname}
</apex:pageBlock>
</apex:form>
</apex:page>
butI'm not getting the fetching records pls help where I done wrong.
Thanks in Advance
my apec class is
public class fetch {
public String accountname{set;get;}
public string destquery{set;get;}
public List<customer__c> cust{set;get;}
public fetch(){
string accountname;
cust=new List<customer__c>();
}
public void show(){
destquery='select Balance__c,City__c,State__c from Customer__c where name=\'' +accountname+'\'';
}
}
My vf page is
<apex:page controller="fetch">
<apex:form >
<apex:pageBlock >
<apex:outputLabel value="Name" /><apex:inputText >{!accountname}</apex:inputText>
<apex:commandButton value="Ok" action="{!show}"/>
</apex:pageBlock>
<apex:pageBlock >
<!-- <apex:pageBlockTable value="{!destquery}" var="a">
<apex:column value="{!a.Balance__c}" />
<apex:column value="{!a.City__c}" />
<apex:column value="{!a.State__c}" />
</apex:pageBlockTable> -->
{!accountname}
</apex:pageBlock>
</apex:form>
</apex:page>
butI'm not getting the fetching records pls help where I done wrong.
Thanks in Advance
You are preparing the query string but you are not querying the records.
you have to use database.query() method and pass the query string as a parameter for this method. And then siplay the records in pageBlock Table
And also in page for pageBlock table you have defined value as destquery which is a string. Instead you need to pass List<customer__c> ie..cust
Try below code
Page
Controller
Mark this as "SOLVED" if your query is Answered
Regards,
Bhanu Mahesh
All Answers
You are preparing the query string but you are not querying the records.
you have to use database.query() method and pass the query string as a parameter for this method. And then siplay the records in pageBlock Table
And also in page for pageBlock table you have defined value as destquery which is a string. Instead you need to pass List<customer__c> ie..cust
Try below code
Page
Controller
Mark this as "SOLVED" if your query is Answered
Regards,
Bhanu Mahesh
my apec class is
So, here is the working code for this. You can replace the object and fields according to your requirement.
VF Page
Controller Class