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

Create a picklist with campaigns.On selecting the campaign ,its associated lead name need to be displayed on pageblocktable or datatable

Bhanu MaheshBhanu Mahesh
Hi Mahi,

Try below code

VF Page
<apex:page controller="GetLeads">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection title="Select Campaign">
              <apex:pageblockSectionItem >
                  <apex:outputLabel value="Campaigns" />
                    <apex:selectList size="1" value="{!selectedCampaign}">
                        <apex:selectOptions value="{!campaignLst}" />
                        <apex:actionSupport event="onchange" action="{!fetchLeads}" rerender="leads"/>
          <apex:outputPanel id="leads">
              <apex:outputPanel rendered="{!displayLeads}">
              <apex:pageBlockSection title="Leads of Selected Campaign" >
                  <apex:pageBlockTable value="{!leadLst}" var="lead" rendered="{!leadLst.size > 0}">
                      <apex:column headerValue="Name" value="{!lead.Name}"/>
                  <apex:outputText value="No Leads for selected Campaign" rendered="{!NOT(leadLst.size > 0)}" />

public class GetLeads {
    public List<SelectOption> campaignLst{get;set;}
    public String selectedCampaign{get;set;}
    public List<Lead> leadLst{get;set;}
    public Boolean displayLeads{get;set;}
    public GetLeads(){
        campaignLst = new List<SelectOption>();
        leadLst =new List<Lead>();
        campaignLst.add(new SelectOption('none','-none-'));
        for(Campaign camp : [SELECT Id,Name FROM Campaign Order By Name ASC]){
           campaignLst.add(new SelectOption(camp.Id,camp.Name));             
    public PageReference fetchLeads(){
        displayLeads = false;
        if(selectedCampaign != 'none'){
            displayLeads = true;
            Set<Id> leadIds = new Set<Id>();
            for(CampaignMember campMem : [SELECT Id, LeadId FROM CampaignMember WHERE CampaignId =:selectedCampaign AND LeadId != NULL]){
                if(campMem.LeadId != null ){
                leadLst = [SELECT Id,Name FROM Lead WHERE Id IN :leadIds];        
        return null;
Mark this as "SOLVED" if your query is Answered

Bhanu Mahesh
i wan to display opportunity name and customers.Can you please help me