1

hey guys i'm trying to avoid nesting my query as such

SELECT
    (
        SELECT

            Body,
            CreatedBy.Name,
            CreatedBy.Email,
            CreatedBy.SmallPhotoUrl,
            SenderId,
            SentDate

        FROM ChatterMessages

        WHERE SentDate > 2013-04-02T00:04:11.000Z

        ORDER BY SentDate ASC

    )

FROM ChatterConversation

By using group by for the ChatterMessage SOBJECT like this,

SELECT

    Body,
    CreatedBy.Name,
    CreatedBy.Email,
    CreatedBy.SmallPhotoUrl,
    SenderId,
    SentDate

FROM ChatterMessage

WHERE SentDate > 2013-04-02T00:04:11.000Z

GROUP BY ConversationId

ORDER BY SentDate ASC

Unfortunetly I'm getting the dreaded MALFORMED_QUERY: Ordered field must be grouped or aggregated: SentDate i've tried aggregating with using GROUP BY Id, ConversationId but it doesn't seem to work, anyone know what I'm doing wrong?

        WHERE SentDate > 2013-04-02T00:04:11.000Z

        ORDER BY SentDate ASC
0

The problem with your 2nd query is that you're not selecting the same relationships between child and parent objects as you were in the original query! You have NO choice but to nest the query to get the same results.

To be a bit more specific as to why your 2nd query isn't working at all, you can't GroupBy the ConversationId if you haven't queried that field. I hope that helps make more sense of what's happening.

That being said, you can still do a GroupBy or OrderBy on your original query to organize the results in whatever manner suits your preferences, provided you're grouping by fields you've queried.

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.