You need to sign in to do that
Don't have an account?
Nag Raj 32
how to display account and their contacts using datatable in VF page
Hi,
I am new to Salesforce, I need to display Account and their contacts in single datatable in vf page, formate as shown below.
please help me in this,
thanks@Regards,
Raj
I am new to Salesforce, I need to display Account and their contacts in single datatable in vf page, formate as shown below.
please help me in this,
thanks@Regards,
Raj
----------------------
Visualforce
----------------------
<apex:page standardController="Opportunity" sidebar="false" doctype="html-5.0" extensions="OpportunityContacts">
<apex:pageBlock title="Main Contact Info">
<apex:pageBlockSection >
<apex:dataTable value="{!oppAllContacts}" var="eachContact">
<apex:column headerValue="Contact First Name" value="{!eachContact.FirstName}"/>
<apex:column headerValue="Contact Last Name" value="{!eachContact.LastName}"/>
<apex:column headerValue="Preferred Contact Time" value="{!eachContact.Preferred_Contact_Time__c}"/>
<apex:column headerValue="Inquiring For" value="{!eachContact.Inquiring_For__c}"/>
<!-- add your other columns here -->
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
------------------------
Extension Controller
------------------------
public class OpportunityContacts {
private final Id oppId;
public List<Contact> oppAllContacts {get;set;}
public OpportunityContacts(ApexPages.StandardController stdController) {
this.oppId = ((Opportunity)stdController.getRecord()).Id;
Opportunity opp = [select id,accountid from opportunity where id = :oppId];
if (opp.AccountId != null) {
oppAllContacts = [select firstname,lastname,AccountId,Preferred_Contact_Time__c,Inquiring_For__c from contact where accountid = :opp.AccountId];
}
}
}
Regards,
Pawan Kumar
Regards,
Pawan Kumar