function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ratheven SivarajahRatheven Sivarajah 

I am trying to grab the firstname, lastname and phone from the related list of contacts

Hey everyone, I am new to salesforce. I have a question I am trying to grab the firstname, lastname and phone from the related list of contacts and display it on a visualforce page 
---------page--------
<apex:page controller="AccountController">
<div style="text-align: center:">
    <p>Name:{!firstName}</p>
    <p>Name:{!lastName}</p>
    <p>Name:{!phone}</p>
</div>
</apex:page>

-------controller-------
public without sharing class AccountController {
    public static string firstName;
    public static string lastName;
    public static string phone;
    public case AccountController() {
        string aId = ApexPages.currentPage(),getParameters().get('id')
        List <opportunity> openList = [select id, FirstName, LastName, phone from contact where accountid = :aId ];
        firstName = openList.FirstName
        lastName = openList.LastName
        phone = openList.phone
    }
}

---Error---
I am getting an error 'AccountController.firstName'

Thank you in advance I really appreciate it!!
SwethaSwetha (Salesforce Developers) 
HI Ratheven, 
Try the code from 
http://salesforcecodes.com/display-related-contacts-of-an-account-using-visualforce-page/

Related: https://www.forcetalks.com/salesforce-topic/how-to-display-names-of-contact-amp-opportunity-related-to-an-account-in-a-visualforce-page/

If this information helps, please mark the answer as best. Thank you
TobyKutlerTobyKutler
Remove the static keyword when instantiating your variables. According to Salesforce documentation "They aren’t transmitted as part of the view state for a Visualforce page." 

controller should be like:
​​​​​​​public without sharing class AccountController {
    public string firstName;
    public string lastName;
    public string phone;
    public case AccountController() {
        string aId = ApexPages.currentPage(),getParameters().get('id')
        List <opportunity> openList = [select id, FirstName, LastName, phone from contact where accountid = :aId ];
        firstName = openList.FirstName
        lastName = openList.LastName
        phone = openList.phone
    }
}

 
Ratheven SivarajahRatheven Sivarajah
@Swetha
I tried the solution on the page you recommended but I am getting 2 different errors
1:duplicate value found: unknown duplicates value on record with id
2:unknown value found: duplicate value on record with id:

--------visualforce page-------
<apex:page  controller="AccountController">
    <apex:form>
        <apex:pageBlock title="Contacts List" id="contacts_list">
        <apex:pageBlockTable value="{! contacts }" var="ct">
        <apex:column value="{! ct.FirstName }"/>
        <apex:column value="{! ct.LastName }"/>
        <apex:column value="{! ct.Title }"/>
        <apex:column value="{! ct.Email }"/>
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>  
</apex:page>

------Apex Class-----
public class AccountController {
    public List<Contact> AccountSummaryController(){
    List<Contact> conresults = [Select Id, FirstName, LastName,Title,Email from Contact where accountid='001Dn0000087GegIAE'];
    return conresults;
    }
}