0

I would like to sort a list with two fields for a visual force page, so it works like this:

Sorted by latest SRA_Date_Time__c(datetime) + by lowest Activity (integer)

Example:

  • one lead has SRA_Date_Time__c - 11.10.2019, Activity 0
  • the other lead has also SRA_Date_Time__c - 11.10.2019, Activity 5

I would like the first lead to be displayed on top, while the other being 2nd.

My query looks like this:

SELECT [fields]
FROM Lead
WHERE [conditions]
ORDER BY SRA_Date_Time__c DESC, Activity_Count__c ASC

However, it seems SOQL is actively ignoring the 2nd part of the sorting and it does not work according to my expectations. Would someone be willing to help me with this issue?

Thanks a lot in advance.

3
  • 1
    The SOQL you show looks right. Can you explain what you are seeing as wrong in the sorting?
    – Phil W
    Oct 11, 2019 at 16:40
  • Could null values be playing a role in what you see? default is NULLS FIRST
    – cropredy
    Oct 11, 2019 at 17:08
  • Your field name indicates a field type of Datetime, not Date. Therefore, two values with the same Date are extremely unlikely to be equal. You have to also consider the time portion of that field.
    – Adrian Larson
    Oct 11, 2019 at 20:51

1 Answer 1

0

Since it is a dateTime field, is it possible that you are dealing with records with the same date, but different times?

If this is the case, the easiest solution would probably be to add a formula field on the obejct that would take the dateTime field and change it into a date, then order by that:

DATEVALUE( SRA_Date_Time__c)

You must log in to answer this question.

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