1

Trying to get field with the earliest date from custom object. Here is my current query

BomaGroups =    [SELECT Name, Location__c FROM Group__c WHERE Location__c =:id]; // Selects the Group I want from Location Master object
MeetingsList2 = [SELECT Name, Group__c, Business_Value__c, Meeting_Date__c, GPS_Meeting_Location__Latitude__s, GPS_Meeting_Location__Longitude__s, 
Group__r.Name FROM Meeting__c WHERE Group__c =:BomaGroups 
ORDER BY Meeting_Date__c]; // Selects Meetings I want with the Groups SOQL  as the where clause

The above queries work fine for getting 1 record that matches the WHERE clause but its supposed to return all the record matching the satisfying the WHERE clause and whose Field value for the date field is the earliest. Thought of using MIN(Meeting_Date__c) but that doesn't work with Lists, so I was thinking of an AND section in the where clause that will select earliest date, Any help would be highly appreciated still a newbie and I just cant seem to get past this one.

Let me try explain what kind of results I'm expecting: With the filter criteria as group 1,

1.Meeting 1 ,10-10-2009 , group1

2.Meeting 2 , 10-10-2009, group1

3.Meeting 3 , 10-10-2009, group1

4.Meeting 1 ,11-10-2009 ,group1

5.Meeting 1 , 12-10-2009, group1

Expected Return #1, Currently returning #1, #4, #5

5
  • Are you getting any error? What is group__c in meeting__c ? is it a lookup? if it is then you should be equating it with a set<Id> rather than list <Group__c>. I am curious what is the output you are getting in MeetingList2
    – Prady
    Commented Oct 28, 2014 at 14:27
  • What happens when you remove the Limit 1? Do you get a large number of results? Also, is it safe to assume that BomaGroups returns more than one result? If so, perhaps you want to do a GroupBy on Group__c so you can then find the earliest from the results that are returned. You might want to look at the SOQL and SOSL Reference to get a better idea of how to sort your results.
    – crmprogdev
    Commented Oct 28, 2014 at 16:03
  • @Prady No, its working as expected. group__c is the master detail relationship between the group and meeting(Child)
    – Rufus K.
    Commented Oct 30, 2014 at 9:02
  • @crmpogdev If I remove the limit 1, it will return all the records. Let me try post an example of results I'm expecting
    – Rufus K.
    Commented Oct 30, 2014 at 9:04
  • @Kollo. Wouldnt adding Limit 1 to the second query return the result you are looking at.
    – Prady
    Commented Oct 30, 2014 at 10:33

1 Answer 1

0

Could you run the second query as a subquery of the first, sorting within the subquery and then retrieving the child record from those results?

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