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
tgganeshtgganesh 

Display custom object record

Hi All,

 

I have created a custom object, using a controller i need to collect a list of records belonging to a custom object and display all the records in a VF Page. Please give me some code snippet to complete this.

 

Thanks in advance :)

Best Answer chosen by Admin (Salesforce Developers) 
tgganeshtgganesh

Thanks Premanath,

 

But i tried and got some solution..

 

Here is the code..

 

<apex:page id="FAQPage" showHeader="false" title="FAQ" standardController="SfFaq__c">
  <apex:composition template="SfdcSiteTemplate">
    <apex:define name="body">  
      <center>
        <table width="100%" height="100%" border="1">
            <thead>
                <tr width="100%"><th><strong>Frequently Asking Question</strong></th></tr>
            </thead>
            <tbody>
                <apex:repeat value="{!SfFaq__c}" var="q">
                <tr height="100%" width="100%">
                    <td height="100px">
                        <apex:outputtext value="{!q.Question__c}"/>
                    </td>
                    <td height="100px">
                        <apex:outputtext value="{!q.Answer__c}"/>
                    </td>
                </tr>
                </apex:repeat>
            </tbody>
            </table>
      </center>
      <br/>
    </apex:define>
  </apex:composition>
</apex:page>

 

public class SiteGetFaq {
    public List<SfFaq__c> FAQuest{get;set;}
    public SiteGetFaq(){
      try{  
        FAQuest = [Select s.SystemModstamp, s.Question__c, s.OwnerId, s.Name, s.LastModifiedDate, s.LastModifiedById, s.IsDeleted, s.Id, s.CreatedDate, s.CreatedById, s.Answer__c From SfFaq__c s ORDER BY s.Name];
        system.debug('Record+++'+FAQuest);
        
      }
      catch(Exception e){
            System.debug('Error Message :'+e.getMessage());
            
        }
      
      }
}

 

All Answers

PremanathPremanath

try this code ,i am using Account object instead you can use your own object and fields names here

 

<apex:page controller="firstinterview">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Data}" var="acc">
<apex:column value="{!acc.Name}"/>
<apex:column value="{!acc.BillingState}"/>
<apex:column value="{!acc.Phone}"/>
<apex:column value="{!acc.Website}"/>
</apex:pageBlockTable>

</apex:pageBlock>
</apex:form>

</apex:page>

 

 

public class firstinterview {


public firstinterview () {
}
List<Account> Varacc;
public firstinterview (ApexPages.StandardController controller) {
}

public List<Account> getData()
{
string str1=Apexpages.currentpage().getParameters().get('id');
Varacc =[Select id,Name,ShippingState,BillingState,Phone,Website from Account];
if(varacc.size()>0)
{
return Varacc;
}
return null;
}

}

 

 

 

if it acceptable plz make it as solution for others it may benfit

tgganeshtgganesh

Thanks Premanath,

 

But i tried and got some solution..

 

Here is the code..

 

<apex:page id="FAQPage" showHeader="false" title="FAQ" standardController="SfFaq__c">
  <apex:composition template="SfdcSiteTemplate">
    <apex:define name="body">  
      <center>
        <table width="100%" height="100%" border="1">
            <thead>
                <tr width="100%"><th><strong>Frequently Asking Question</strong></th></tr>
            </thead>
            <tbody>
                <apex:repeat value="{!SfFaq__c}" var="q">
                <tr height="100%" width="100%">
                    <td height="100px">
                        <apex:outputtext value="{!q.Question__c}"/>
                    </td>
                    <td height="100px">
                        <apex:outputtext value="{!q.Answer__c}"/>
                    </td>
                </tr>
                </apex:repeat>
            </tbody>
            </table>
      </center>
      <br/>
    </apex:define>
  </apex:composition>
</apex:page>

 

public class SiteGetFaq {
    public List<SfFaq__c> FAQuest{get;set;}
    public SiteGetFaq(){
      try{  
        FAQuest = [Select s.SystemModstamp, s.Question__c, s.OwnerId, s.Name, s.LastModifiedDate, s.LastModifiedById, s.IsDeleted, s.Id, s.CreatedDate, s.CreatedById, s.Answer__c From SfFaq__c s ORDER BY s.Name];
        system.debug('Record+++'+FAQuest);
        
      }
      catch(Exception e){
            System.debug('Error Message :'+e.getMessage());
            
        }
      
      }
}

 

This was selected as the best answer