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
Naveen Ashok SirivellaNaveen Ashok Sirivella 

How to display pageblock when click on button in visualforce page

Hi All,

I am new to salesforce.
I have on requirment.When i click on "Show All leads" button on that time only records need to display with new page block.
Below are my code:
-----------------------------------
VF page
----------------------
<apex:page standardController="Lead" Extensions="DisplayingListofrecords_Controller">

<apex:form >
  <apex:pageBlock title="For buttons">
       <apex:commandButton action="{!ShowLeads}" value="Show Leads" reRender="Details"/>
  </apex:pageBlock>
</apex:form>
<apex:outputPanel id="Details">
<apex:actionStatus startText="Requesting............">
  <apex:pageBlock title="Displaying List of accounts" id="Showlistofleads" rendered="false">
    <apex:dataTable value="{!leadlist}" var="a" cellpadding="4" border="1">
        <apex:column >
              <apex:facet name="header">Name</apex:facet>
              {!a.Name}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">Company</apex:facet>
              {!a.Company}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">Status</apex:facet>
              {!a.Status}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">Industry</apex:facet>
              {!a.Industry}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">Email</apex:facet>
              {!a.Email}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">LeadSource</apex:facet>
              {!a.LeadSource}
        </apex:column>  
        <apex:column >
              <apex:facet name="header">Lead Score</apex:facet>
              {!a.Lead_Score__c}
        </apex:column>          
    </apex:dataTable>
</apex:pageBlock>
</apex:actionStatus>
</apex:outputPanel>
</apex:page>
Controller
-------------------
public with sharing class DisplayingListofrecords_Controller {

    Public List<Lead> leadlist {get;set;}
    public DisplayingListofrecords_Controller(ApexPages.StandardController controller) {
     
   
    }
    
    public PageReference ShowLeads()
    {
         leadlist = [select Name,Company,Status,Industry,Email,LeadSource,Lead_Score__c from lead];
         
         return null;
    }

}
 
Naveen Ashok SirivellaNaveen Ashok Sirivella
User-added image
in the above screen shot when click on show leads button on that time only all leads needs to display in seperate block with out refreshing entire page.

Please help me on this
DevADSDevADS
Hey Naveen,

Paste below code-
<apex:page standardController="Lead" Extensions="DisplayingListofrecords_Controller">

    <apex:form id="theform">
      <apex:pageBlock title="For buttons">
           <apex:commandButton action="{!ShowLeads}" value="Show Leads" reRender="theform"/>
            <apex:actionStatus startText="Requesting............"></apex:actionStatus>
            <apex:pageBlock title="Displaying List of accounts" id="Showlistofleads" rendered="true">
                <apex:dataTable value="{!leadlist}" var="a" cellpadding="4" border="1">
                    <apex:column >
                          <apex:facet name="header">Name</apex:facet>
                          {!a.Name}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">Company</apex:facet>
                          {!a.Company}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">Status</apex:facet>
                          {!a.Status}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">Industry</apex:facet>
                          {!a.Industry}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">Email</apex:facet>
                          {!a.Email}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">LeadSource</apex:facet>
                          {!a.LeadSource}
                    </apex:column>  
                    <apex:column >
                          <apex:facet name="header">Lead Score</apex:facet>
                          {!a.Lead_Score__c}
                    </apex:column>          
                </apex:dataTable>
            </apex:pageBlock>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public with sharing class DisplayingListofrecords_Controller {

    Public List<Lead> leadlist {get;set;}
    public DisplayingListofrecords_Controller(ApexPages.StandardController controller) {
     
   
    }
    
    public PageReference ShowLeads()
    {
         leadlist = [select Name,Company,Status,Industry,Email,LeadSource from lead];
         return null;
    }

}

Hit Best answer if it resolved your issue.
Happy Coding.
 
Naveen Ashok SirivellaNaveen Ashok Sirivella
User-added image

Code looks good but in the above screen both button display and recods displaying on nested page block.
but i want 2 button click page block and records display page block both are differrent when i click on button list will display in new page block not on same page block.

Thanks,
Naveen Ashok S
Naveen Ashok SirivellaNaveen Ashok Sirivella
Hi All,

I want Code help to learn salesforce development .

can any one help me please.

Thanks,
Naveen Ashok S