You need to sign in to do that
Don't have an account?
mohit tripathi
Basic Custom Controller
Hi Guys
When I Am trying to fetch contact's Record from Account via custom controller, I Am unable to fetch contact's record from an account in vf page.
I feel controller is fine but I Am missing something in VF page.
Here is my controller-
public class AccCustomOppController {
Public Account Acct {get; set;}
public AccCustomOppController (){
String AcctId = ApexPages.CurrentPage().getParameters().get('id');
Acct= [select name, Rating, id from Account Where Id =: AcctId];
}
public List<Contact> ContactList{
get{
ContactList = [ select name, Email , Department from Contact where AccountId = :Acct.Id ];
return ContactList;
}
set;
}
Public PageReference Save(){
update Acct;
return new pageReference ('/' + Acct.ID);
}
}
and VF page is-
<apex:page controller="AccCustomOppController">
<apex:form >
<apex:pageblock Title="Account Custom Controller check">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save the updated Account Information"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Acct.Name}"/>
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageBlock>
<apex:pageBlockTable value="{!ContactList}" var="Con">
<apex:column value="{!con.Name}" title="Contact Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please let me know what am I doing Wrong.
Thanks in Advance
When I Am trying to fetch contact's Record from Account via custom controller, I Am unable to fetch contact's record from an account in vf page.
I feel controller is fine but I Am missing something in VF page.
Here is my controller-
public class AccCustomOppController {
Public Account Acct {get; set;}
public AccCustomOppController (){
String AcctId = ApexPages.CurrentPage().getParameters().get('id');
Acct= [select name, Rating, id from Account Where Id =: AcctId];
}
public List<Contact> ContactList{
get{
ContactList = [ select name, Email , Department from Contact where AccountId = :Acct.Id ];
return ContactList;
}
set;
}
Public PageReference Save(){
update Acct;
return new pageReference ('/' + Acct.ID);
}
}
and VF page is-
<apex:page controller="AccCustomOppController">
<apex:form >
<apex:pageblock Title="Account Custom Controller check">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save the updated Account Information"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Acct.Name}"/>
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageBlock>
<apex:pageBlockTable value="{!ContactList}" var="Con">
<apex:column value="{!con.Name}" title="Contact Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Please let me know what am I doing Wrong.
Thanks in Advance
Mainly in your <apex:pageBlockTable value="{!ContactList}" var="Con"> you are using Con with capital C but in <apex:column value="{!con.Name}" title="Contact Name"/> you are using lower con.
just change
var="Con"to var="con". your all ohter code is fine.Thanks
Ronty
All Answers
Use this code it's working fine, prints all it's related contacts.
Thanks
Devanshu
Replace your ContactList method on your AccCustomOppController
To
Thanks
Ronty
Mainly in your <apex:pageBlockTable value="{!ContactList}" var="Con"> you are using Con with capital C but in <apex:column value="{!con.Name}" title="Contact Name"/> you are using lower con.
just change
var="Con"to var="con". your all ohter code is fine.Thanks
Ronty
Your code is working fine. I found only one issue. Just updated the Con to con
<apex:pageBlock >
<apex:pageBlockTable value="{!ContactList}" var="con">
<apex:column value="{!con.Name}" title="Contact Name"/>
</apex:pageBlockTable>
</apex:pageBlock>
NOTE:- You need to pass Account Record ID in URL like below screen shot
YOUR URL SHOULD BE LIKE BELOW
BASE_URL/apex/YOUR_PAGE_NAME?id=0016A000006WIuj
Pass record ID according to your org.
This was so silly of me.
You all are champ.
Thanks and Cheers.