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
Rodolfo CalvoRodolfo Calvo 

Cannot call contacts in method

Hello team, 

Can someone tells me what I am doing wrong with my code?
I am trying to call the contacts by clicking a button
<apex:sectionHeader title="Contact Duplicates"/>
              <!-- SEARCH TAB -->
                <apex:actionRegion >  
                  <apex:outputPanel id="top" layout="block">
                  <!--[Styles CCS]-->
                    <apex:outputLabel for="txtSearch"/>
                    <apex:inputText id="txtSearch" html-placeholder="Search your account" value="{!searchStringCnt}" />
                      <apex:commandButton id="btnGo" value="Search" action="{!SearchCnt}" rerender="searchResults"></apex:commandButton>
                  <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
                    <apex:pageBlock id="searchResults"> 
                      <apex:pageBlockTable value="{!resultsCnt}" var="c" id="tblResults">
                      <apex:column headerValue="Selection">
                            <apex:inputCheckbox id="ckDuplicates"></apex:inputCheckbox>
                          <apex:facet name="header">
                            <apex:outputPanel >Firstname</apex:outputPanel>
                        <!--//Column Type-->
                          <apex:facet name="header">
                            <apex:outputPanel >Lastname</apex:outputPanel>
                        <!--//Column Phone Number-->
                        <apex:column >
                          <apex:facet name="header">
                            <apex:outputPanel >Phone Number</apex:outputPanel>
Here is the method
    //performs the keyword search
    public List<Account> resultsCnt {get;set;}
    //public Contact[] cnt {get;set;}
    public string searchStringCnt{get;set;}
      public PageReference searchCnt() {
        return null;
        // prepare the query and issue the search command
      private void runSearchCnt() {
        //prepare query string for complex serarches & prevent injections
        resultsCnt = performSearchCnt(searchStringCnt);               

      //run the search and return the records found. 
      private List<Account> performSearchCnt(string searchStringCnt) {
        //String will make a callback of contacs
        //cnt = [SELECT id, firstName, lastName, phone FROM Contact];
        String soql = 'SELECT id, firstName, lastName, phone FROM Contact';
        if(searchStringCnt != '' && searchStringCnt != null)
        //soql = soql +  ' where name LIKE \'%' + searchStringCnt +'%\'';
        //soql = soql + ' limit 25';
        return database.query(soql); 
      // used by the visualforce page to send the link to the right dom element
      public string getFormTagCnt() {
        return System.currentPageReference().getParameters().get('frm');
      // used by the visualforce page to send the link to the right dom element for the text box
      public string getTextBoxCnt() {
        return System.currentPageReference().getParameters().get('txt');

Thanks in advance
Best Answer chosen by Rodolfo Calvo
Hello Rodolfo,
What exactly are you trying to do ?
I see that you have created,
<apex:pageBlockTable value="{!resultsCnt}" var="c" id="tblResults">
And you havent used the 'C' variable anywhere to refer to your contacts in the VF page.
The Contact you used has no reference at all in the class.
In simple, try to do as below .
1.If you use a List<Contact>  , try assigning this as the value for the dataTable and assign a variable to it.
2.Start using this variable to access each element from the list.

By this way you will be able to retrieve the values onto the page.


Rohit Alladi