1

I have a list of event locations i'm trying to return to a visual force page:

public class EventDataExt {

 private final Event__c e;

 public EventDataExt(ApexPages.StandardController stdController) {
    this.e = (Event__c)stdController.getRecord();
 }

 public List <Event_Location__c> getels () {

    List <Event_Location__c> els = [select Name, City__c from Event_Location__c where Event__c=:e.Id];     
    return els;       
 }
}

What I'm trying to do is append values to the end of each object in the list. So in addition to Name and City__c that are fields from the object, i want to add anotherkey => anothervalue to the end of each object. Any help is much appreciated.

UPDATE:

i'm getting other data that i need from the disp_list: controller extension is here:

public with sharing class xExtDataExtension {

private final Event__c e;

public xExtDataExtension(ApexPages.StandardController stdController) {
    this.e = (Event__c)stdController.getRecord();
}

public list<wrapperclass> disp_list{get;set;}  
public list<wrapperclass> theEvent {get;set;}

public class wrapperclass{  


    public Integer Registered{get;set;}  
    public Integer Attended{get;set;}  
    public Integer Buyer{get;set;}  
    public Integer ANB{get;set;}
    public Integer RNA{get;set;}
    public String Name{get;set;}

}

public xExtDataExtension() {  
   disp_list=new List<wrapperclass>();         
   List<Event_Location__c>els=[select id, Name from Event_Location__c];  
   for(Event_Location__c el:els){

       integer fetchRegistered = [select count() from CampaignMember where Event_Location__c=:el.id AND Event_Location_Time__c !=null];
       integer fetchAttended = [select count() from CampaignMember where Event_Location__c=:el.id AND Event_Location_Time__c !=null AND Checkin__c=true];
       integer fetchBuyer = [select count() from CampaignMember where Event_Location__c=:el.id AND Event_Location_Time__c !=null AND Checkin__c=true AND Lead.IsConverted=true];
       integer fetchANB = 0;
       integer fetchRNA = 0;

       wrapperclass w=new wrapperclass();  

       w.Registered=fetchRegistered;  
       w.Attended=fetchAttended;  
       w.Buyer=fetchBuyer;
       w.ANB=fetchANB;
       w.RNA=fetchRNA;  
       w.Name=el.Name;

       disp_list.add(w);
    }  

}  

}

what i can't get, is the main object data, what i assume would be the standard controller that i assign in my vf page standardController="Event__c". when i try to output data from e.whatever it comes up blank. i need to access the main object too. it's odd, because if i switch my vf page to use the extension as the controller, then the Event__c data shows up, but the custom list from disp_list disappears. i'm sure i'm missing something easy and fundamental@#$%^&

1 Answer 1

3

You will need to create a wrapper class and use that as your collection type. Something like:

public List<EventLocationWrapper> locations { get; private set; }

public class EventLocationWrapper
{
    public Event_Location__c record { get; private set; }
    public Object otherProperty { get; private set; }

    public EventLocationWrapper(Event_Location__c record)
    {
        this.record = record;
        this.otherProperty = 'Some value';
    }
}

Example

After you have a wrapper class, your controller might be written like this:

public with sharing class EventDataExt {

    private final Event__c e;

    public EventDataExt(ApexPages.StandardController stdController) {
        this.e = (Event__c)stdController.getRecord();
    }

    public List<EventLocationWrapper> getelWrappers () {

        // query for the events - this list never be null, but may be empty
        List <Event_Location__c> els = [select Name, City__c from Event_Location__c where Event__c=:e.Id];

        // create the list of EventLocationWrapper to be returned
        List<EventLocationWrapper> eventLocationWrappers = new List<EventLocationWrapper>();

        // for each item in the query list add it to the wrapper and augment with additional values
        for (Event_Location__c el : els) {

            // use the constructor to place this event inside the wrapper
            EventLocationWrapper wrapper = new EventLocationWrapper(el);

            // add some additional stuff
            wrapper.otherProperty = "Something Else";

            // add the wrapper to the list to be returned
            eventLocationWrappers.add(wrapper);
        }

        return eventLocationWrappers;       
    }

    public class EventLocationWrapper
    {
        public Event_Location__c record { get; set; }
        public String otherProperty { get; set; }

        public EventLocationWrapper(Event_Location__c record)
        {
            this.record = record;
            this.otherProperty = 'Some value';
        }
    }
}

The VF markup to reference a wrapper like this might look similar to this pseudocode:

<apex:dataTable value="{!elWrappers}" var="wrapper">

    <!-- value from the wrapper itself -->
    <apex:outputText value="{!wrapper.otherProperty}" />

    <!-- value from the sObject within the wrapper -->
    <apex:outputField value="{!wrapper.record.City__c}" />
</apex:dataTable>
5
  • You sir are awesome. I really appreciate your help.
    – dkhendo
    Commented Mar 4, 2015 at 23:06
  • Don't forget to click the "accept" under the voting arrows, if this answer resolves your issue. Glad to assist!
    – Mark Pond
    Commented Mar 4, 2015 at 23:30
  • wow missed your update a while ago. i'm getting closer thanks to your examples but i'm still an issue. from your answer and some data i found on a blog post, i've been able to create the ad-hoc list disp_list to return what i need - what i can't get to work is the main object that the controller is based off - here's the controller:
    – dkhendo
    Commented Mar 5, 2015 at 4:32
  • i plugged in what suggested above into a separate class and tested - getting this error when i try to save the visualforce page: Error: Unknown constructor 'EvExt.EvExt()'
    – dkhendo
    Commented Mar 5, 2015 at 14:39
  • figured it out, super new to wrappers. thanks again for your time.
    – dkhendo
    Commented Mar 5, 2015 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .