+ Start a Discussion
satakshisatakshi 

How to display record from custom object on VF Page?

Hello,

I am inserting some records when i click on custom button. Button is on parent object. I am creating child records of that parent object. I want to show all this records on visualforce page. I have written the code. But nothing is displaing. Can anyone please help me?
VF SHOWDTP


<apex:page standardController="MTP__c"  extensions="showCalender">
<apex:form >
 <apex:pageBlock title="All Dtp">
 <apex:pageblockTable value="{!mydtpList}" var="item">
 <apex:column value="{!item.Name}"/> 
 <apex:column value="{!item.Date__c}"/> 
 <apex:column value="{!item.Visit_type__c}"/> 
 <apex:column value="{!item.Food_Expenses__c}"/> 
</apex:pageblockTable>
 </apex:pageBlock> 
 </apex:form>
</apex:page>


=============================================

Controller

public class showCalender {
    public List<DTP__c> mydtpList {set;get;}
     public  id tid{get;set;}


    public showCalender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 
        getMydtpList();
     }
       public List<DTP__c> getMydtpList(){
      
    
        List<DTP__c> mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid limit 50];

        return mydtpList ;
        }
    //List<DTP__c>  mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];

    }

Regards,
Satakshi
Best Answer chosen by satakshi
Nayana KNayana K
public class showCalender {
    public List<DTP__c> mydtpList {set;get;}
     public  id tid{get;set;}


    public showCalender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 
        fetchMydtpList();
     }
       public void fetchMydtpList(){
      
    
        mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid limit 50];

        
        }
    
    }

update controller with this code.

All Answers

Nayana KNayana K
public class showCalender {
    public List<DTP__c> mydtpList {set;get;}
     public  id tid{get;set;}


    public showCalender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 
        fetchMydtpList();
     }
       public void fetchMydtpList(){
      
    
        mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid limit 50];

        
        }
    
    }

update controller with this code.
This was selected as the best answer
AshlekhAshlekh
Hi Satakshi,

Your code is good just remove the "public List<DTP__c> mydtpList {set;get;}" line and " getMydtpList();" line from constructor. 

Or you can compare your code with below code.
 
public class showCalender 
{
    public  id tid{get;set;}
    public showCalender(ApexPages.StandardController controller)
     {
          MTP__c rec= (MTP__C)controller.getRecord();
          if(rec !=null)        
             tid = rec.id;
           System.debug('**************Verify Id is here**************'+tid); 
     }
     
    public List<DTP__c> getMydtpList()
    {

         List<DTP__c> mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from                     DTC__c  where MTP__c=:tid limit 50];
        return mydtpList ;
        }
    }
-Thanks
Ashlekh Gera
 
satakshisatakshi
Thanks you both of you.. both code is working. Thanks for your time and appreciation
 
Ankit Arora 30Ankit Arora 30
I need help.

I have a similar situation, where the Master object is Contact and the Detail object is TargetX_SRMb__Financial_Aid__c. I want to display the data of the detail object on the Master object.

APEX CLASS:

public class FinAidData {

public  id fid{get;set;}

public FinAidData(ApexPages.StandardController controller)
     {
     
          Contact con= (Contact)controller.getRecord();
          if(con !=null)        
          fid = con.id;
     }

public List<TargetX_SRMb__Financial_Aid__c> getFinaidList(){

List<TargetX_SRMb__Financial_Aid__c> finaidList = [Select Name, TargetX_SRMb__Amount__c,NYIT_Amount_Accepted__c,TargetX_SRMb__Accept_Date__c from TargetX_SRMb__Financial_Aid__c  where TargetX_SRMb__Contact__c =: fid];
return finaidList;
}
}


VISUALFORCE PAGE:

<apex:page standardController="Contact" extensions="FinAidData">
<apex:form>
<apex:pageBlock title="Financial Aid Information">
<apex:pageBlockTable value="{!finaidList}" var="finaid">
<apex:column value="{!finaid.Name}"/>
<apex:column value="{!finaid.TargetX_SRMb__Amount__c}"/>
<apex:column value="{!finaid.NYIT_Amount_Accepted__c}"/>
<apex:column value="{!finaid.TargetX_SRMb__Accept_Date__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form >
</apex:page>

I am getting an error message when I try to save VF page and Apex Class. Please help me. I can't find the problem.

VF : Error: Unknown property 'ContactStandardController.finaidList'
APEX: Error: Compile Error: The method List<TargetX_SRMb__Financial_Aid__c> getfinaidresults() is referenced by Visualforce Page (Financial_Aid_Data) in salesforce.com. Remove the usage and try again. at line 13 column 45