You need to sign in to do that
Don't have an account?
prati@salesforce
Vf page and controller
Hi folks...
Here is my vf page code and controller code. But I am getting an error called Unknown property 'ContactgivenId.con. I have defined getter and setter in my controller. Any help will be appreciated.. Thanks in advance..
Vf page code_______________________
<apex:page id="pgId" controller="ContactgivenId">
<Apex:form>
<apex:pageBlock>
<Apex:pageblockSection title="Accounts">
<apex:pageBlockTable value="{!acct}" var="account">
<Apex:column headervalue="Account id">
<Apex:outputPanel >
<Apex:outputText value="Click" />
<apex:actionSupport event="onclick" action="{!getContact}" rerender="contactBlock" >
<Apex:param name="accountId" assignTo="{!acctId}" value="{!account.Id}"/>
</apex:actionSupport>
</apex:outputPanel >
</apex:column>
<Apex:column headervalue="Account name">
<Apex:outputField value="{!account.Name}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock id="contactBlock">
<Apex:pageblockSection title="Contacts">
<apex:pageBlockTable value="{!con}" var="contact">
<Apex:column headervalue="Contact id">
<Apex:outputField value="{!contact.Id}"/>
</apex:column>
<Apex:column headervalue="Contact name">
<Apex:outputField value="{!contact.firstName}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
___________________________________________Controller________________________________
public class ContactgivenId {
public List<Account> acct{get; set;}
public List<Contact> cont{get; set;}
public String acctid{get; set;}
public ContactgivenId(){
acct=new List<Account>();
cont= new List<Contact>();
acct=[select id,name from account LIMIT 10];
}
public void getContact(){
cont=[select firstname, lastname, phone from contact where account.id= :acctid];
}
}
Here is my vf page code and controller code. But I am getting an error called Unknown property 'ContactgivenId.con. I have defined getter and setter in my controller. Any help will be appreciated.. Thanks in advance..
Vf page code_______________________
<apex:page id="pgId" controller="ContactgivenId">
<Apex:form>
<apex:pageBlock>
<Apex:pageblockSection title="Accounts">
<apex:pageBlockTable value="{!acct}" var="account">
<Apex:column headervalue="Account id">
<Apex:outputPanel >
<Apex:outputText value="Click" />
<apex:actionSupport event="onclick" action="{!getContact}" rerender="contactBlock" >
<Apex:param name="accountId" assignTo="{!acctId}" value="{!account.Id}"/>
</apex:actionSupport>
</apex:outputPanel >
</apex:column>
<Apex:column headervalue="Account name">
<Apex:outputField value="{!account.Name}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock id="contactBlock">
<Apex:pageblockSection title="Contacts">
<apex:pageBlockTable value="{!con}" var="contact">
<Apex:column headervalue="Contact id">
<Apex:outputField value="{!contact.Id}"/>
</apex:column>
<Apex:column headervalue="Contact name">
<Apex:outputField value="{!contact.firstName}" />
</apex:column>
</apex:pageBlockTable>
</Apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
___________________________________________Controller________________________________
public class ContactgivenId {
public List<Account> acct{get; set;}
public List<Contact> cont{get; set;}
public String acctid{get; set;}
public ContactgivenId(){
acct=new List<Account>();
cont= new List<Contact>();
acct=[select id,name from account LIMIT 10];
}
public void getContact(){
cont=[select firstname, lastname, phone from contact where account.id= :acctid];
}
}
Apex
VF
Mark it as Solved, if it works.
All Answers
use following code in your VF page and it should work fine.
There was some issue with var name -> contact
cont = [select id, firstname from contact where accountid =: acctid];
Apex
VF
Mark it as Solved, if it works.
Are you clicking on the TEXT "Click" and not somewhere else? If not, do that.
If the problem persits check manually whether there are associated contacts in your SFDC org for those accounts.
Consider sharing screenshots and your final code, if its not resolved.
Thanks once again..
1. Populating a selectList/PageBlockTable/Dependent picklists
2. Redirect users to aonther page
There are few other scenarios I can't recall though.
But don't query the DB on each button click, its against SFDC best practices.
Always bulkify your SOQL query for effective use of your org limits.
Learn more about it here:
https://developer.salesforce.com/page/Apex_Code_Best_Practices