Thursday, June 20, 2013

Salesforce - Display data from Custom object to PageBlockTable using Apex

Here i have provided code sample to understand, how to display data from custom objects to PageBlockTable. I have chosen pageBlocktable because it has predefined style. Don't want to use any css styles for that.
Apex Design Code:
  1. <apex:page controller="ViewUserController">
  2. <apex:form >
  3. <apex:sectionHeader subtitle="All Users" title="Users" />
  4. <apex:pageBlock >
  5. <apex:pageBlockTable value="{!allusers}" var="a">
  6. <apex:column headervalue="Name" value="{!a.Name__c}" />
  7. <apex:column headervalue="Age" value="{!a.Age__c}" />
  8. <apex:column headervalue="Class" value="{!a.Class__c}" />
  9. </apex:pageBlockTable>
  10. </apex:pageBlock>
  11. </apex:form>
  12. </apex:page>
Apex Controller Code:
  1. public class ViewUserController
  2. {
  3. public List<User__c> allusers;
  4. public List<User__c> getAllUsers()
  5. {
  6. if(allusers==null)
  7. {
  8. allusers=[SELECT Name__c,Age__c,Class__c from User__c];
  9. }
  10.  
  11. return allusers;
  12. }
  13. }

No comments:

Post a Comment