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
#DD#DD 

Getting VF too many soql queries error

i am getting VF too many soql queries error, here is the code.

when I click switch from buttons, 'webinar' to 'Email'
public with sharing class campaignFilterController {
    public String bltypeEmail {get; set;}
    Database.QueryLocator qLoc;   
    public Integer totalPages { get; set; } 
    public ApexPages.StandardSetController campaignsSetController {
        get {
            if(bltypeEmail == 'Conference') {
                typeConference('Conference');
                calcPages();
            }
            else if(bltypeEmail == 'Email') {
                typeConference('Email');
            }
            else if(bltypeEmail == 'Webinar') {
                typeConference('Webinar');
            }
            return campaignsSetController;
        }
        set;
    }
    public Contact objContact;
    public String currentContRecordId;
    Decimal dtotalPages;
    Integer iRecordsPerPage = 1;
    public List<Campaign> Campaigns {
        get {
            return (List<Campaign>)campaignsSetController.getRecords();
        }
    }
 
    public campaignFilterController () {
        currentContRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        bltypeEmail = ApexPages.CurrentPage().getparameters().get('Type');
        objContact = [select id,accountid from contact where id=:currentContRecordId];
        System.debug('@@@@@@@' +currentContRecordId);
        System.debug('@@@@@@@' +objContact);
        System.debug('@@@@@@@' +objContact.Id);
        
               
        // You can initialize the set controller using a SOQL query:
        String query;
        query = 'SELECT Id, Name, Type, Status,(select Id from CampaignMembers  where ContactId = \'' + objContact.Id + '\') FROM Campaign';
        campaignsSetController = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        System.debug('@@@@@@@' +objContact.Id);
                       
        // Create the set controller
 
        // Set the number of records to be displayed per page and calculate the number of pages.
        //campaignsSetController.setPageSize(iRecordsPerPage);
        //dtotalPages = (campaignsSetController.getResultSize() / campaignsSetController.getPageSize());
        //dtotalPages = Math.floor(dtotalPages) + ((Math.mod(campaignsSetController.getResultSize(), iRecordsPerPage)>0) ? 1 : 0);
        //totalPages = Integer.valueOf(dtotalPages);
        calcPages();
               
    }
   
    public void typeConference (String Type) {
        //Database.QueryLocator qLoc;
        String query;
        String campaignType = Type;
        //currentContRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        //bltypeEmail = ApexPages.CurrentPage().getparameters().get('Type');
        //objContact = [select id,accountid from contact where id=:currentContRecordId];
      
        query = 'Select Id, Name, Type, Status,(select Id from CampaignMembers where ContactId= \'' + objContact.Id + '\') from Campaign where Type= \'' + campaignType + '\'';
        campaignsSetController = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        calcPages();
    }
        public void calcPages(){
                campaignsSetController.setPageSize(iRecordsPerPage);
                dtotalPages = (campaignsSetController.getResultSize() / campaignsSetController.getPageSize());
                dtotalPages = Math.floor(dtotalPages) + ((Math.mod(campaignsSetController.getResultSize(), iRecordsPerPage)>0) ? 1 : 0);
                totalPages = Integer.valueOf(dtotalPages);
        }
}

<apex:page Controller="campaignFilterController" sidebar="false" standardStylesheets="true" tabStyle="Contact">
    <apex:form id="campaignDetails" >
        <apex:pageMessages />
        <apex:pageBlock title="Campaign Filter" >
            <apex:pageBlockButtons >
                <apex:outputPanel rendered="{!totalPages > 1}" >
                    <table border="0" style="width:100%; text-align: right">
                        <tr>
                            <td style="width:100%">&nbsp;</td>
                            <td style="vertical-align: middle">
                                <apex:actionStatus id="statusPaging">
                                    <apex:facet name="start">
                                        <apex:outputPanel >Please wait...</apex:outputPanel>
                                    </apex:facet>
                                    <apex:facet name="stop" />
                                </apex:actionStatus>
                            </td>
                            <td style="text-align: center; white-space: nowrap">
                                <b>Page:</b><br/>{!campaignsSetController.PageNumber} of {!totalPages}
                            </td>
                            <td style="vertical-align: middle">
                            <apex:commandButton value="Conference" reRender="campaignDetails" >
                            <apex:param name="bltypeEmail" assignTo="{!bltypeEmail}" value="Conference"/>
                            </apex:commandButton>
                            </td>
                            <td style="vertical-align: middle">
                            <apex:commandButton value="Email" reRender="campaignDetails" >
                            <apex:param name="bltypeEmail" assignTo="{!bltypeEmail}" value="Email"/>
                            </apex:commandButton>
                            </td>
                            <td style="vertical-align: middle">
                            <apex:commandButton value="Webinar" reRender="campaignDetails" >
                            <apex:param name="bltypeEmail" assignTo="{!bltypeEmail}" value="Webinar"/>
                            </apex:commandButton>
                            </td>
                            <td style="vertical-align: middle">
                                <apex:commandButton value="|<" action="{!campaignsSetController.First}"
                                disabled="{!Not(campaignsSetController.HasPrevious)}" rerender="campaignDetails" status="statusPaging"/>
                            </td>
                            <td style="vertical-align: middle">
                                <apex:commandButton value="<" action="{!campaignsSetController.Previous}"
                                disabled="{!Not(campaignsSetController.HasPrevious)}" rerender="campaignDetails" status="statusPaging"/>
                            </td>
                            <td style="vertical-align: middle">
                                <apex:commandButton value=">" action="{!campaignsSetController.Next}"
                                disabled="{!Not(campaignsSetController.HasNext)}" rerender="campaignDetails" status="statusPaging"/>
                            </td>
                            <td style="vertical-align: middle">
                                <apex:commandButton value=">|" action="{!campaignsSetController.Last}"
                                disabled="{!Not(campaignsSetController.HasNext)}" rerender="campaignDetails" status="statusPaging"/>
                            </td>
                        </tr>
                    </table>
                </apex:outputPanel> 
            </apex:pageBlockButtons>
 
            <apex:pageBlockTable id="TabRefresh" value="{!Campaigns}" var="campaign" >
                <apex:column value="{!campaign.Name}"/>
                <apex:column value="{!campaign.Status}"/>
                <apex:column value="{!campaign.Type}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>