0

I have created a Wrapper class to present data from different objects Event__c and Campaign. The class works fine when I hardcode the values for the SOQL statements but when I assign the dynamic values retrieved form a visual force page the table is empty. selectedCampaignValue and selectedEventValue are values retrieved from pick lists.

Wrapper Controller

 public with sharing class WrapperClassExtension {


    public String selectedCampaignValue {get; set;}
    public String selectedEventValue {get; set; }
    public List<WrapList> countList {get; set;}

    public WrapperClassExtension(ApexPages.StandardController controller) {


    }

    public List<WrapList> getCounts(){

          countList = new List<WrapList>();

    for(Campaign c : [SELECT id,Name,isActive,NumberOfContacts FROM Campaign WHERE Name LIKE :selectedCampaignValue AND IsActive = True LIMIT 1]){
        for(Event__c ev : [SELECT id,Event_Id__c,Event_Name__c,Event_Attendees_Count__c  FROM Event__c WHERE Event_Name__c LIKE :selectedEventValue LIMIT 1]){
     /*Create a new wrapper and add it to list*/
     countList.add(new WrapList(c,ev));
   }
   }
   return countList;
 }

    public class WrapList {

    public Campaign cCount { get; set; }
    public Event__c evCount { get; set; }


    public WrapList(Campaign c, Event__c ev) {
        this.cCount = c;
        this.evCount = ev;
    }


    }


}

Visualforce

<apex:pageBlock id="results_count" title="Count" rendered="{!attending != null}">
      <apex:pageMessages />
      <apex:pageBlockSection title="DelegateManager Total - {!selectedEventValue}" columns="1" collapsible="true">
        <apex:outputText style="font-style:italic"
          value="Delegates attending the specified event are listed below. Click the 'Sync All' button to synchronize your Salesforce records with DelegateManager delegates. If you wish to receive an email with a csv file containing failed syncs for the event then press 'Email Csv'."></apex:outputText>
        <apex:pageBlockTable value="{!Counts}" var="c" rows="1">
          <apex:column headerValue="DelegateManager Total" style="width:30px;">
            <apex:outputText value="{!c.evCount.Event_Attendees_Count__c}"/>
          </apex:column>
          <apex:column headerValue="Campaign Members Total" style="width:75px;">
            <apex:outputText value="{!c.cCount.NumberOfContacts}"/>
          </apex:column>
        </apex:pageBlockTable>
      </apex:pageBlockSection>
    </apex:pageBlock>
  • 1
    Are you sure you are receiving good values for these two parameters? – Jeremy Nottingham May 4 '17 at 12:53
  • just noticed those values return null on the debug log however i am using those in other classes and work fine. thats strange @JeremyNottingham – Kyri Z. May 4 '17 at 13:21
1

If you want to do a "contains" search, then you need to wrap the input in wildcard characters (%). For example:

String campaignSearchTerm = '%' + selectedCampaignValue + '%';
String eventSearchTerm = '%' + selectedEventValue + '%';
for ([SELECT ... FROM Campaign WHERE Name LIKE :campaignSearchTerm LIMIT 1]) { ... }
  • Tried that as well but not getting results still – Kyri Z. May 4 '17 at 13:16

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.