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
sunfishettesunfishette 

Partner Portal display pulling data from custom object

I am trying to pull data from four custom fields on my custom object to display them in my visual force page.  I have only been using salesforce for a few days, and I am completely stuck.

 

I have custom object: Book

with custom fields: Book Title, Author Name, Book Cost, Book Genre

 

I want to loop through each record on my custom object and display them on my visual force page in my partner portal.  I have an Apex class:

 

public class getAllBooks {
    public getAllBooks(ApexPages.StandardController Controller) {
    }
    public Books__c[]getBookDetail(){
        Book__c[]bookList;
        bookList = [SELECT Books__c.Book_Title__c,
                             Book__c.Author_Name__c,
                             Book__c.Book_Cost__c,
                             Book__c.Book_Genre__c
                        FROM Book__c];
        return bookList;
    }
}

and my VF page:

<apex:page standardController="Books__c" extensions="getAllBooks"

    <apex:form>
        <apex:pageBlock>
            <apex:PageBlockTable value="{!getAllBooks}" var="book">
                <apex:column value="{!book.Book_Title__c}" headerValue="Book Title" />
                <apex:column value="{!book.Author_Name__c}" headerValue="Author Name" />
                <apex:column value="{!book.Book_Cost__c}" headerValue="Book Cost" />
                <apex:column value="{!book.Book_Genre__c}" headerValue="Book Genre" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>

</apex:page>

 

Error: Unknown property 'Book_cStandardController.getAllBooks'

 

I have no idea what to try next. 

Any suggestions would be helpful.  Laymens terms are also helpful, as I am not the sharpest Apex/Visualforce programmer around!

Thanks in advance.

  
Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

---------- apex class-----------

 

public class getAllBooks {

public Books__c bookList{get;set;}

    public getAllBooks(ApexPages.StandardController Controller) {

    }

 

 public Books__c[] getBookDetail(){

 {

 bookList=new Books__c();

 bookList = [SELECT id,Book_Title__c,Author_Name__c,Book_Cost__c,Book_Genre__c FROM Book__c];

 return bookList;

 }

  

}

 

----------------- vf page-------------

 

<apex:page standardController="Books__c" extensions="getAllBooks">

 

    <apex:form>

        <apex:pageBlock>

            <apex:PageBlockTable value="{!BookDetail}" var="book"> <!-- change  getAllBooks with BookDetail -->

                <apex:column value="{!book.Book_Title__c}" headerValue="Book Title" />

                <apex:column value="{!book.Author_Name__c}" headerValue="Author Name" />

                <apex:column value="{!book.Book_Cost__c}" headerValue="Book Cost" />

                <apex:column value="{!book.Book_Genre__c}" headerValue="Book Genre" />

            </apex:pageBlockTable>

        </apex:pageBlock>

    </apex:form>

 

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

---------- apex class-----------

 

public class getAllBooks {

public Books__c bookList{get;set;}

    public getAllBooks(ApexPages.StandardController Controller) {

    }

 

 public Books__c[] getBookDetail(){

 {

 bookList=new Books__c();

 bookList = [SELECT id,Book_Title__c,Author_Name__c,Book_Cost__c,Book_Genre__c FROM Book__c];

 return bookList;

 }

  

}

 

----------------- vf page-------------

 

<apex:page standardController="Books__c" extensions="getAllBooks">

 

    <apex:form>

        <apex:pageBlock>

            <apex:PageBlockTable value="{!BookDetail}" var="book"> <!-- change  getAllBooks with BookDetail -->

                <apex:column value="{!book.Book_Title__c}" headerValue="Book Title" />

                <apex:column value="{!book.Author_Name__c}" headerValue="Author Name" />

                <apex:column value="{!book.Book_Cost__c}" headerValue="Book Cost" />

                <apex:column value="{!book.Book_Genre__c}" headerValue="Book Genre" />

            </apex:pageBlockTable>

        </apex:pageBlock>

    </apex:form>

 

</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
sunfishettesunfishette

The solution you listed worked, I did not change my class, I only changed my VF page to the suggested BookDetail that you listed.

Worked like a charm.  Thank you SO very much.

 

Now I have one last piece of this puzzle to put together.  I need to be able to sort the books on the field Book_Genre ... (I have them broken into 3 categories, I know there are MANY genres, but I am trying to start small.)

 

Is that something I would do directly in my apex class? I want the sort to occur on page load.  Should I write a method that sorts them for me and breaks them into three arrays?  Any thoughts, or pointers to steer me in the right direction? 

Thanks again!!!