0

On click of a button on VF page records of the custom object should be displayed....i have written the code for it there are no errors but the records are not being displayed on click of the button. I am new to salesforce platform Please help?

MY CODE:

-------- VF Page -------------

<apex:page controller="RecordFetch">
<apex:form >
<apex:pageBlock title="Bookings List">
<apex:commandButton value="Display Records" action="{!GetRecordPage}" reRender="recMatch" id="bor"/>

<apex:pageblocktable id="bookrec" rendered="{!display}" value="{!RecordFetching}" var="fetch">

    <apex:column value="{!fetch.id}"/>
    <apex:column value="{!fetch.name}"/>
    </apex:pageblocktable>   
    </apex:pageBlock>

</apex:form>
</apex:page>

---------Apex class-----------

public class RecordFetch {

public List<Booking__c> bdoc;

public boolean display{get; set;}

public RecordFetch() {
     display = false;
}

Public PageReference GetRecordPage(){

    display = true;
    GetRecordFetching();

   return null;   
}


Public List<Booking__c> GetRecordFetching(){

    bdoc =  new List<Booking__c>();

   List<Booking__c> listitem = [Select Id, Name From Booking__c];

if(listitem.size() > 0)
{
        bdoc.addall(listitem);        
}    
          return bdoc;
}
}
0

Try Below code

Just reRender theForm on apex:CommandButton and it will work

VFP

<apex:page controller="RecordFetch">
<apex:form id="theForm">
<apex:pageBlock title="Bookings List">
<apex:commandButton value="Display Records" action="{!GetRecordPage}" reRender="theForm" id="bor"/>

<apex:pageblocktable id="bookrec" rendered="{!display}" value="{!RecordFetching}" var="fetch">

    <apex:column value="{!fetch.id}"/>
    <apex:column value="{!fetch.name}"/>
    </apex:pageblocktable>   
    </apex:pageBlock>

</apex:form>
</apex:page>

Apex Class

public class RecordFetch {

public List<Booking__c> bdoc;

public boolean display{get; set;}

public RecordFetch() {
     display = false;
}

Public PageReference GetRecordPage(){

    display = true;
    GetRecordFetching();

   return null;   
}


Public List<Booking__c> GetRecordFetching(){

    bdoc =  new List<Booking__c>();

   List<Booking__c> listitem = [Select Id, Name From Booking__c];

if(listitem.size() > 0)
{
        bdoc.addall(listitem);        
}    
          return bdoc;
}
}
  • Thanx for pointing out my mistake......this was easy......Thank you :) – Deeksha Gaur Jan 5 '17 at 13:10
  • There's a problem in the class. You don't need to call the method 'GetRecordFetching' in 'GetRecordPage'. This method is automatically called by the page block table. – Martin Lezer Jan 5 '17 at 13:16
0

You should try this for your VF page:

<apex:page controller="RecordFetch">
<apex:form >
<apex:pageBlock id="recMatch" title="Bookings List">
<apex:commandButton value="Display Records" action="{!GetRecordPage}" reRender="recMatch" id="bor"/>

<apex:pageblocktable id="bookrec" rendered="{!display}" value="{!RecordFetching}" var="fetch">

    <apex:column value="{!fetch.id}"/>
    <apex:column value="{!fetch.name}"/>
    </apex:pageblocktable>   
    </apex:pageBlock>

</apex:form>
</apex:page>

And this for your controller:

public class RecordFetch {

public List<Booking__c> bdoc;

public boolean display{get; set;}

public RecordFetch() {
     display = false;
}

Public void GetRecordPage(){

    display = true;
}


Public List<Booking__c> GetRecordFetching(){

    bdoc =  new List<Booking__c>();

   List<Booking__c> listitem = [Select Id, Name From Booking__c];

if(listitem.size() > 0)
{
        bdoc.addall(listitem);        
}    
          return bdoc;
}
}
  • No problem ! Glad I could help. – Martin Lezer Jan 5 '17 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.