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
conpasconpas 

"dataTable" return empty data

 Hello,

I have an problem. I try to use data table apex function in my page, but show me empty always. The controller return good data, but something happens in "apex:dataTable". This is my code:

<apex:page controller="exampleCon" cache="false">
  <apex:dataTable value="{!contacts}" var="c" id="theTable" rowClasses="odd,even" styleClass="tableClass">

        <apex:column><apex:facet name="header">Name</apex:facet>
            <apex:outputText value="-{!c.Name}"/>
        </apex:column>

        <apex:column>
            <apex:facet name="header">Phone</apex:facet>
            <apex:outputText value="-{!c.Phone}"/>

        </apex:column>

    </apex:dataTable>

</apex:page>


And my controller:

public class exampleCon {

    List<Contact> contacts;

    public List<Contact> getcontacts() {
        contacts = [select Name, Phone from Contact limit 10];     
        return contacts;
    }
}


Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
AshanAshan

Check whether you have permission to read Contact object and its fields

All Answers

LuckkyLuckky

Hi 

 

You have to use getContacts() instead of getCases.OR You have to change the  datatable value in VFpage to cases instead of contacts. and You have to write  list<Contact> contacts=new list<Comntact>();

 

Thanks

conpasconpas

I change the function name to getContacts(), but this continue to fail.

LuckkyLuckky

Hi 

 

Use list<contact> contacts=new list<contact>(); or you can directly use list<contact> contacts=[select.......]; in get method

 

thanks.

conpasconpas

Dont work.

 

If I try to extract information and put is in a variable, work perfectly:

 

I add this in my controller:

 

 

String Phone;

 

 

.......................

 

    public String getPhone() {
    Phone = contacts.get(0).Phone;
    return Phone;
    }

 

 

And in my page:

 

   <apex:outputText value="{!Phone}"/>

 

 

And show me a phone number.

LuckkyLuckky

there is no problem its working Properly. i didn't get what u want?

conpasconpas

I want to show a list of contacts using  apex:dataTable. I try to say you that do not fail in apex class, fail in the apex page.

 

Thanks

rohitsfdcrohitsfdc

everything is looking fine in your code, please verify if your query is returning some results.

 

AshanAshan

Check whether you have permission to read Contact object and its fields

This was selected as the best answer
conpasconpas

I have a Trial Enterprise account, this affects?

rohitsfdcrohitsfdc

it shouldnt. please post your entire code.

Rahul SharmaRahul Sharma

I guess its some security issue, Same code works perectly in my org.

conpasconpas

Ashan wrote:

Check whether you have permission to read Contact object and its fields


Thanks, now work perfectly.