+ Start a Discussion
Mike Schumacher 2Mike Schumacher 2 

Display Invitees from EventRelations in a visualforce page

I am trying to display all the invitees from an event in a visualforce page.  I am using the EventRelations query in the Event as shown in other posts.  That seems to be working ok.   I have been able to reference the information from the EventRelations queryresult but had to list the array value.  I want to simply list the Names of the Invitees to an event on a separate row like this:

Mike Schumacher
Kristen Bazin
Olivier Kerdiles

I am struggling with the best practice and syntax to reference data from a SOQL where the WSDL defines a field as a 'tns:QueryResult'

**apex class**
public class Provi_VisitReport_SOQL {
public List<Event> Events2 {get; set;}
public Provi_VisitReport_SOQL(){

Events2 =
[select e.Id,e.Subject,e.Type,e.EndDateTime,e.CreatedBy.Full_Name__c,e.Account.Name,e.WhatId,
 (Select Id, RelationId, EventId, Status, Relation.Name From EventRelations)
 from Event e where e.WhatId = :lVRId and IsChild = false and
EndDateTime > Today];

**Visualforce page code**
        <apex:pageBlockTable value="{!Events2}" var="Event2">
            <apex:column >
                <apex:facet name="header">Active Event Subject</apex:facet>
                <apex:outputText value="{!Event2.Subject}"/>
            <apex:column >
                <apex:facet name="header">Id</apex:facet>
                <apex:outputText value="{!Event2.Id}"/>
            <apex:column >
                <apex:facet name="header">EventRelations Info</apex:facet>
                <apex:outputText value="{!Event2.EventRelations[0].Relation.Name}"/>

David Roberts 4David Roberts 4
Me, too!
Reporting just one attendee using [0] works fine but how do we get the complete list?
      <apex:pageBlockTable value="{!anEvent}" var="Event2">
                <apex:column headerValue="Invitee"  value="{!Event2.EventRelations.Relation.Name}"/>  

doesn't work.
Nearest I can find is https://help.salesforce.com/apex/HTViewSolution?id=000003207&language=en_US
and I'm just trying to get my head round it.
David Roberts 4David Roberts 4
I eventually got there. I have a 'training' campaign from which I identify training events and then iterate to get the delegates. Hold in a class for display on the page. Hope this framework is useful to others. (VFPage to follow...)
public class vwTrainingBookingController{
//Dave Roberts Sept 2016
      //see https://developer.salesforce.com/docs/atlas.en-us.202.0.pages.meta/pages/pages_controller_custom.htm
       public class HoldAttendees   // used to store the attendees from EventRelations.
        public Id hRelationID {get; set;}        //This will store the attendee.
        public String hSubject {get; set;}
        public String hAttendeeName {get; set;}
        public Boolean hIsParent {get; set;}
        public Boolean hIsWhat {get; set;}
        public DateTime hStartDateTime {get; set;}
        public HoldAttendees(){}                   //Empty constructor.
    public List<HoldAttendees> CombinedData {get; set;}    //This will store the list of EventRelations as well as the event detail.
    public Event anEvent {get; private set;}
      public vwTrainingBookingController(){
            Id campId = '7018E00000089o4QAA'; //default for debugging/querying
        list<Campaign> listIds = [select Id from Campaign where IsActive = true and Name like 'Virtual%' limit 1]; //for debug
            campId = listIds[0].Id;
            anEvent = [SELECT Id, WhatId, Subject, isAllDayEvent, StartDateTime, EndDateTime, (Select Id, RelationId, EventId, Status, Relation.Name From EventRelations) from Event where whatId = :campId limit 1];
            //for(Event evnt: [select Id, WhatId, Subject, isAllDayEvent, StartDateTime, EndDateTime from Event where whatId = :campId]){ //and startdatetime < 2018-01-01T00:00:00Z]){
        //use the holding class
        CombinedData = new List<HoldAttendees>();
        integer iCount = 0;
        //contacts have isWhat false; opportunities have true; hence the additional where clause
        for (EventRelation Node : [Select relation.name, relationID,isParent,isWhat from EventRelation where eventId = :anEvent.Id and isWhat = false])    //Query and loop through all the related names i.e. attendees.
            iCount = iCount +1;
            HoldAttendees temp = new HoldAttendees();   // Create temp to insert into the list Records.
            temp.hRelationID = Node.relationID;
            temp.hAttendeeName = Node.relation.Name;
            temp.hIsParent = Node.isParent;
            temp.hIsWhat = Node.isWhat;
            system.debug('related to '+iCount+' id = '+temp.hRelationID);
            system.debug('related to '+iCount+' name = '+temp.hAttendeeName+ ' isParent='+temp.hIsParent);
            system.debug('related to '+iCount+' isWhat='+temp.hIsWhat);
            temp.hStartDateTime = anEvent.StartDateTime;   //from the event so repeated per attendee
            temp.hSubject = anEvent.Subject;
      public PageReference save(){
            //construct only...incomplete for the above
                  upsert (anEvent);
            } catch (system.DmlException e){
                  return null;
return null; //return to edit page
David Roberts 4David Roberts 4
Here’s the VisualForce Page
<apex:page controller="vwTrainingBookingController" tabstyle="Event">
<!-- https://.../apex/vwtrainingbooking -->
<apex:form >
<apex:pageBlock title="Training Booking" mode="edit">
      <apex:pageMessages />
      <apex:pageBlockSection >
            <apex:inputField value="{!anEvent.Id}"/> 
            <apex:inputField value="{!anEvent.WhatId}"/>
            <apex:inputField value="{!anEvent.Subject}"/>
            <apex:inputField value="{!anEvent.isAllDayEvent}"/>
            <apex:inputField value="{!anEvent.StartDateTime}"/>
            <apex:inputField value="{!anEvent.EndDateTime}"/>
<apex:pageBlockTable value="{!anEvent}" var="Event2">
            <apex:column >
                <apex:facet name="header">Active Event Subject</apex:facet>
                <apex:outputText value="{!Event2.Subject}"/>
            <apex:column >
                <apex:facet name="header">Id</apex:facet>
                <apex:outputText value="{!Event2.Id}"/>
         <apex:pageBlockTable title="Attendees" value="{!CombinedData}" var="index">    <!-- The pageBlockTable iterates through the list of the custom Class -->
            <apex:column headerValue="Name" value="{!index.hAttendeename}"/>    <!--Display the related names information -->
                  <apex:column headerValue="StartDate" value="{!index.hStartDateTime}"/>    <!--Display/Repeat the event information -->
            <apex:column headerValue="Subject" value="{!index.hSubject}"/>
      <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Save" action="{!Save}"/>
David Roberts 4David Roberts 4
And here’s the test for the controller.
 * This class contains unit tests for validating vwTrainingBookingController
 * 5/9/2016 Dave Roberts
private class vwTrainingBookingControllerTest {
    static testMethod void myUnitTest() {
        PageReference pageRef = Page.vwTrainingBooking;
        vwTrainingBookingController theCont = new vwTrainingBookingController();
        theCont.save(); //if you want to check the save method