+ Start a Discussion
HIRAL PUROHITHIRAL PUROHIT 

How to create pageBlockTable in custom object

I have created app related to university.In this for Student object I need to show some information in one table with 4 columns.
Please guide me how to create table in custom object using Visualforce.

Here I am posting my code which I tried.

<apex:page Controller="Student">
   <apex:pageBlock title="Course Details">
     <apex:pageBlockTable value="{!Student_c}" var="stu">
      <apex:column value="{!stu.Sr_no__c}"/>
      <apex:column value="{!stu.Course_1__c}"/>
      <apex:column value="{!stu.Professor__c}"/>
      <apex:column value="{!stu.Final_Grade__c}"/>
</apex:pageBlockTable>

      </apex:pageBlock>
</apex:page>
----------------------------------------------------------------------
Error: Unknown property 'String.Sr_no__c'



Thanks.
Best Answer chosen by HIRAL PUROHIT
SFDC Coder 1SFDC Coder 1
Hi Hiral,

To show the data in the table from the object your controller should look as below.

public class Student {

    public list<Student__c> getStudent_c() {
        //your business logic
    }
}

Ex. consider a scenario where you want to show all the record from Student__c then your controller should look as below.

public class Student {

    public list<Student__c> getStudent_c() {
       return [select Sr_no__c, Course_1__c, Professor__c, Final_Grade__c  from Student__c];
    }
}

If this helps you in solving your problem then mark it as Best Answer.

All Answers

SFDC Coder 1SFDC Coder 1
Hi Hiral,
I am assuming that the method getStudent_c in your custom controller is not returning the proper list type.Kindly have a look in that(it should look alike list<Student__c>).

And if this is not the issue then share your controller code.

P.S. if above-mentioned solution helps you then mark it a Best Answer. 
 
HIRAL PUROHITHIRAL PUROHIT
This is my controller code:

public class Student {

    public String getStudent_c() {
        return null;
    }

-----------------------------------------------
it's showing following error:

Error: Unknown property 'String.Sr_no__c'
HIRAL PUROHITHIRAL PUROHIT
Thanks for reply.
please help with this.
LakshmanLakshman
You need to return List<Student__c> in your getter instead of string. 
SFDC Coder 1SFDC Coder 1
Hi Hiral,

To show the data in the table from the object your controller should look as below.

public class Student {

    public list<Student__c> getStudent_c() {
        //your business logic
    }
}

Ex. consider a scenario where you want to show all the record from Student__c then your controller should look as below.

public class Student {

    public list<Student__c> getStudent_c() {
       return [select Sr_no__c, Course_1__c, Professor__c, Final_Grade__c  from Student__c];
    }
}

If this helps you in solving your problem then mark it as Best Answer.
This was selected as the best answer
HIRAL PUROHITHIRAL PUROHIT
Ohh Yeah.It's working.
Thank you so much Snjeev and  Lakshman for your help.
One more thing please....
I want to show this table to my Students tab(Object:Student).I created a section named course details on Student object,in this section I want to show this table.So how can I use my visualforce code there?
HIRAL PUROHITHIRAL PUROHIT
Hi
I tried overriding by using  'Buttons, Links, and Actions' but then it's come up with just a one section(only VF code).
I have two section in my tab  (1. Student Detail ,2.Course Detail) . And I want to replace this Course Details section  with my VF code. And want to keep Student Detail section as it is.