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

Controller extension for accounts to pull back contacts
Im new to controller extensions and I'm not finding the SF help pages particularly helpful in this area.
I have a VF page that shows account information. I need to also include the contacts associated with the account.
My Extension is below:
public class myAccountControllerExtension {
public Account account { get; }
public Contact contact { get; }
public myAccountControllerExtension(){
contact = null;
getContacts();
}
private void getContacts(){
List<Account> accounts = new List<Account>([
SELECT Id, Name, AccountNumber,
(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true)
FROM Account]);
}
}
When I reference the extension in my page I receive the error:
Error: Unknown constructor 'myAccountControllerExtension.myAccountControllerExtension(ApexPages.StandardController controller)'
Can anyone advise why?
I have a VF page that shows account information. I need to also include the contacts associated with the account.
My Extension is below:
public class myAccountControllerExtension {
public Account account { get; }
public Contact contact { get; }
public myAccountControllerExtension(){
contact = null;
getContacts();
}
private void getContacts(){
List<Account> accounts = new List<Account>([
SELECT Id, Name, AccountNumber,
(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true)
FROM Account]);
}
}
When I reference the extension in my page I receive the error:
Error: Unknown constructor 'myAccountControllerExtension.myAccountControllerExtension(ApexPages.StandardController controller)'
Can anyone advise why?
Replace you constructer with below code
Please mark it as best solution to your problem if it does solve your problem.
IF it helps you than please mark it as a solution and ENJOY APEX
Compile Error: Variable is not visible: acct at line 7 column 9
Change:
To
Note, most of the examples on here are written off the top of our heads, so they'll likely contain compile errors like this.
Error: Unknown constructor 'myAccountControllerExtension.myAccountControllerExtension(ApexPages.StandardController controller)'
Error: Unknown property 'AccountStandardController.contact'
This is coming on my VF page:
<apex:page standardController="Account" extensions="myAccountControllerExtension">
<apex:pageBlock title="Contacts">
{!contact.Name}
</apex:pageBlock>
Use below code if you want to display all contact associated with an account.
<apex:pageBlockTable value="{!cont}" var="con" >
{!con.Name}
</apex:pageBlockTable>
<apex:pageBlock title="Contacts" >
<apex:pageBlockTable value="{!cont}" var="con" >
{!con.id}
{!con.Name}
</apex:pageBlockTable>
</apex:pageBlock>
If I change this to:
<apex:pageBlock title="Contacts" >
{!cont}
</apex:pageBlock>
I receive a list of IDs which do correspond to contacts. Why is the pageblocktable not showing anything?