+ Start a Discussion
Koustubh KulkarniKoustubh Kulkarni 

I cant retrieve list of records from the custom object on VF page?

Hi,
I have one custom object named EmplyeeTopicRating__c is on detail side of contact standard object.Based on the name of contact i want to fetch list of records from EmplyeeTopicRating__c. so i have written custom controller for it.It didnt give me any error but it doesnt fetches values on EmplyeeTopicRating__c object.so please give me solution.
**************my controller***********************************
public class contactextention 
{

    public contact cont{get;set;}
    public PageReference save() 
    {    update cont;
        return null;
    }


    public contactextention() {
    String acctId = ApexPages.currentPage().getParameters().get('id');
     cont = [Select Name From contact Where Id = :acctId];
   }
 
    public list<EmplyeeTopicRating__c> ratings1
    { get {
           ratings1 =[select Employee_name__c,Employee_name__r.ContactRole__r.Name,TopicPriorityRecord__r.Priority__c,quarter__c,Ratings__c,Year__c,
                TopicPriorityRecord__r.Topic_Name__r.Group_Name__r.Name,TopicPriorityRecord__r.Topic_Name__r.Name from EmplyeeTopicRating__c where Employee_name__c=:cont.name];
          return ratings1;
         }
        set;
        }
    public String getGreeting() 
    {
        return 'Hello ' + cont.name + ' (' + cont.id + ')';
    }
    
}
*******************VF page***********************
<apex:page controller="contactextention">
{!Greeting}
    <apex:form >
        
        <Apex:pageBlock >
        <apex:pageblockButtons >
             <apex:commandButton action="{!save}" value="save" />
        </apex:pageblockButtons>
        <apex:pageBlockSection >
        <apex:pageBlockTable value="{!ratings1}" var="etr">
                  
                  <apex:column headerValue="Year">
                  <apex:inputField value="{!etr.Year__c}"/>
                  </apex:column>
                  <apex:column headerValue="Quarter">
                  <apex:outputField value="{!etr.quarter__c}"/>
                  </apex:column>
                  <apex:column headerValue="Role name">
                  <apex:outputField value="{!etr.TopicPriorityRecord__r.Role__r.Name}"/>
                  </apex:column>
                  <apex:column headerValue="Priority no">
                  <apex:outputField value="{!etr.TopicPriorityRecord__r.Priority__c}"/>
                  </apex:column>
                  <apex:column headerValue="Ratings">
                  <apex:inputField value="{!etr.Ratings__c}"/>
                  </apex:column>
                  <apex:column headerValue="Topic Name">
                  <apex:outputField value="{!etr.TopicPriorityRecord__r.Topic_Name__r.Name}"/>
                  </apex:column>
        </Apex:pageblockTable>
        </apex:pageBlockSection>
        </Apex:pageBlock>
    </apex:form>
</apex:page>

please show whats wrong in the code
Best Answer chosen by Koustubh Kulkarni
Koustubh KulkarniKoustubh Kulkarni
hi,ok i got the answer...actually i was refering field employee name as 
 Employee_name__c but instead of using '__c' i should have used '__r' as it has master detail relationship with contact.Thanks

All Answers

Ricky ThedaRicky Theda
So, there is no records listed on your custom pages? My suggestion is, make sure your query is returning a record. Try to querying from workbench or you can add this to your code: system.debug("EmplyeeTopicRating Size:" + ratings1.size());
Koustubh KulkarniKoustubh Kulkarni
Thanks ricky,I think my querry is not returning any records. But why, is it something wrong with it. I am a newbie here so please help me out.
 
Ricky ThedaRicky Theda
Since it was custom object and custom controller I can't check it on my salesforce org. But here is some suggestion:
1. make sure this
cont = [Select Name From contact Where Id = :acctId];
is valid and returning values.
2. make sure this cont.name variable is returning any values.
where Employee_name__c=:cont.name




 
Koustubh KulkarniKoustubh Kulkarni
cont.name retrieves the proper record field
 
Ricky ThedaRicky Theda
Try your query in workbench.
https://workbench.developerforce.com/login.php
Koustubh KulkarniKoustubh Kulkarni
it gives me error-sorry no records found....whats the problem with my querry?
Ricky ThedaRicky Theda
Please make sure you have record on that object and please let me see your query that you run in workbench.
Koustubh KulkarniKoustubh Kulkarni
select Employee_name__c,Employee_name__r.ContactRole__r.Name,TopicPriorityRecord__r.Priority__c,quarter__c,Ratings__c,Year__c,
                TopicPriorityRecord__r.Topic_Name__r.Group_Name__r.Name,TopicPriorityRecord__r.Topic_Name__r.Name from EmplyeeTopicRating__c where Employee_name__c='sandesh Ganjare'
Koustubh KulkarniKoustubh Kulkarni
hi,ok i got the answer...actually i was refering field employee name as 
 Employee_name__c but instead of using '__c' i should have used '__r' as it has master detail relationship with contact.Thanks
This was selected as the best answer