5

I've got 2 related custom Objects:

Bgroup(Master) & Meetings(detail).

I'm displaying a Google map of the meeting records in the Bgroup VF page with a custom controller. Everything is working fine except the map is showing all the meetings instead of only the meetings of one record in Bgroup. Any clues?

Any help about getting ID of the selected master object(bgroup) record and using it in a SOQL query to filter records of the detail object(Meeting) would be extremely helpful.

Here's my controller class:

public with sharing class GoogleMap_Meeting_Controller {

    public List<Meeting__c> MeetingsList {get;set;}

    public GoogleMap_Meeting_Controller() {

        MeetingsList = [SELECT Group__r.Group__c, GPS_Location__Latitude__s, GPS_Location__Longitude__s FROM Meeting__c  LIMIT 10];

    } // end constructor
} // end class
1
  • 3
    How you are planning to get the Bgroup Id? Can user select the Bgroup from the visualforce page?
    – highfive
    Oct 1, 2014 at 9:02

3 Answers 3

0

I used the '__r' to get the previously selected ID from the master object and it worked. Thanks

  MeetingsList = [SELECT Name, Group__r.Id, Meeting_Date__c, GPS_Meeting_Location__Latitude__s,     GPS_Meeting_Location__Longitude__s FROM Meeting__c WHERE Group__r.Id =:id ORDER BY Meeting_Date__c DESC LIMIT 10 OFFSET 1]; 
0

You should access all child meetings of parent by doing like this

List<Group__c> gList = [select Id ,(select GPS_Location__Latitude__s, GPS_Location__Longitude__s FROM Meeting__c ) from Group__c where id=: parentId];

and can access like this

gList[0].Meeting__c 
0
0

I think you should use the StandardController and use your class as its extension

OR Pass the id of Bgroup record as id from pageparameter.

Using one of above way you will get id of parent in any field say 'BgroupId'.

Now generate your SOQL query like below.

MeetingsList = [SELECT Group__r.Group__c, GPS_Location__Latitude__s, GPS_Location__Longitude__s FROM Meeting__c  WHERE Bgroup__c = :BgroupId];

You must log in to answer this question.

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