0

I have 3 objects.

Event, Invite & Attendee

Event - > Invite (one Event to Many Invites) Master Detail relationship Invite has event details

Attendee - > Invite (one Attendee to Many Invites) Master Detail relationship Invite has Attendee details

Now I want to fetch Attendee from Invites which belong to a particular meeting i.e, fetch Attendee details from Meeting details.

Parent --> Child --> Parent

Is this possible. Please Help.

I used the following Query. It is fetching me all the Attendees irrespective of the meeting.

List<Attendee__c> attns = [select id,name,Attendee_Email__c,Country__c ,(select id,name,Request_Status__c from Invites__r where Meeting__r.name=:meetName) from Attendee__c];

Please help .

Thank you.

1
  • 1
    you can create 2 queries and try to match those considering invitees in a map Feb 7 '17 at 5:58
1

Based on the Event fetch Invitees.

Map<Id, Invites__c> inviteeMap = new Map<Id,Invites__c>([SELECT Id, Name, Request_Status__c 
                                                        FROM Invites__c 
                                                        WHERE Invites__r.EventId =:EventId]);

Now, based on the Invitees, retrieve Attendees.

List<Invites__c> lstInvitee =   [SELECT Attendee__r.id, 
                                        Attendee__r.name,
                                        Attendee__r.Attendee_Email__c,
                                        Attendee__r.Country__c 
                                        FROM Invites__c 
                                        WHERE Id IN:inviteeMap.keySet()];
2
  • Thank you . But after this also we are fetching list of Invites only. I want to get Attendee objects and use them for update, edit etc. Can this be acheived using the attendee fields in the fetched invite?
    – Paps
    Feb 7 '17 at 9:28
  • Like to change attendee name, if I change Attendee__r.name field in the Invite, will it work? Thank you
    – Paps
    Feb 7 '17 at 9:29
0

What @Santanu Boral has told in comments is a good way to do it. Have 2 queries and then match using apex.

However, if you HAVE to use a single query for this, you can do the below:

List<Attendee__c> attns = new List<Attendee__c>();
for(Invite__c inv : [select Id, Attenee__c, Attenee__r.Name, Attenee__r.Attendee_Email__c, Attenee__r.Country__c from Invite__c where Meeting__r.name=:meetName])
{
    Attendee__c att = new Attendee__c();
    att.Id = inv.Attenee__c;
    att.Name = inv.Attenee__r.Name;
    att.Attendee_Email__c = inv.Attenee__r.Attendee_Email__c;
    attns.add(att);
}

You have your list of Attendees in attns

0

Use this query to fetch Attendee from Invites which belong to a particular Meeting :

List<Meeting__c> meetList = new List<Meeting__c>([Select name from Meeting__c]);
List<string> meetName = new List<string>();

for(Meeting__c obj:meetList){
    meetName.add(obj.name);
}

List<Attendee__c> attns = new List<Attendee__c>();
attns = [Select id, name, Attendee_Email__c, Country__c from Attendee__c  where ID IN (Select Attendee_lk__c from Invites__c where Meeting__r.name=:meetName)];
3
  • Used this. attns = [Select id,name,Attendee_Email__c,Country__c from Attendee__c where ID IN (Select Attendee_lk__c from Invite__c where Meeting__r.name=:meetName)]; It is not fetching any results
    – Paps
    Feb 7 '17 at 9:50
  • Getting an empty list
    – Paps
    Feb 7 '17 at 9:51
  • @Paps Check edited answer. Let me know if any query. Feb 7 '17 at 11:07

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.