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
Dan JonesDan Jones 

Fetching Data from Event Object and Contact Object

Hello all,

I've had a problem accessing information from the Contact object, via a lookup in the Event object. WhoId can't seem to get Phone Numbers, Mobile Numbers, E-Mail addresses etc... Which I need.

I've managed to write the following which, based on the event ID, fetches the information I want.

List<Event> e1 = new List<Event>();
e1 = [SELECT Id, WhoId FROM Event WHERE Id ='00UD000000SyFMB'];
System.debug('@@@@@'+e1);

Set<id> WhoId = new Set<id>();
for(event e2 : e1) {
    whoId.add(e2.whoId);
}

List<Contact> c = [SELECT Name, Phone, Email FROM Contact WHERE Id IN : WhoId];
System.debug('@@@@@'+c);
Running this as an anonymous script returns the data I want, I'm just having trouble articulating it into a wrapper script so I can call information from 2 objects on the same row.

Hopefully I've explained my problem well enough!

Thank you!

Dan JonesDan Jones
I've had some luck now.

I've done the following:
public class wrapperClassController {
    public List<cContact> contactList {get; set;}

    public List<cContact> getContacts() {
        if(contactList == null) {
            contactList = new List<cContact>();
            List<Event> e1 = new List<Event>();

            e1 = [SELECT Id, WhoId FROM Event WHERE Id ='00UD000000SyFMB']; 

            Set<id> WhoId = new Set<id>(); 
            for(event e2 : e1) { 
                whoId.add(e2.whoId); 
            }

            for(Contact c : [SELECT Name, Phone, Email FROM Contact WHERE Id IN : WhoId]) {
                contactList.add(new cContact(c));
            }
        }
        return contactList;
    }

    public class cContact {
        public Contact con {get; set;}

        public cContact(Contact c) {
            con = c;
        }
    }
}

This will pull through the contact record based on that event Id, but now I'm stuck on how to actually pull through that events records.

Any help would be massively appreciated.