You need to sign in to do that
Don't have an account?
kailash chandra 25
how to use date function CALENDAR_MONTH() in orderby clause in SOQL
I want to get records of contact based on Birthdate.
eg: i need to display contact records in ASC order of next 60 days. so how to use GROUP BY CALENDAR_MONTH(Birthdate) ASC .
If I use GROUP BY Birthdate ASC It will return date in ascending order.
I am trying SOQL query like this
select id, name,PhotoUrl,Birthdate from Contact WHERE Birthdate != null AND Birthdate = NEXT_N_DAYS:60 ORDER BY CALENDAR_MONTH(Birthdate) ASC, DAY_IN_MONTH(Birthdate) ASC LIMIT 5 OFFSET 0
[object Object]: Ordered field cannot be aggregated in a query that is not grouped: CALENDAR_MONTH(Birthdate)
I need this solution through SOQL without using apex
Do you have any solution to sort birthdate based on month and date then please help me
eg: i need to display contact records in ASC order of next 60 days. so how to use GROUP BY CALENDAR_MONTH(Birthdate) ASC .
If I use GROUP BY Birthdate ASC It will return date in ascending order.
I am trying SOQL query like this
select id, name,PhotoUrl,Birthdate from Contact WHERE Birthdate != null AND Birthdate = NEXT_N_DAYS:60 ORDER BY CALENDAR_MONTH(Birthdate) ASC, DAY_IN_MONTH(Birthdate) ASC LIMIT 5 OFFSET 0
[object Object]: Ordered field cannot be aggregated in a query that is not grouped: CALENDAR_MONTH(Birthdate)
I need this solution through SOQL without using apex
Do you have any solution to sort birthdate based on month and date then please help me
I think, your expected result provided by aggregate result.
I provide some sample code, just try it.
All Answers
If you simply do order by Birthdate ASC, you will get records according to ascending order of birthdate for next 60 days.
select id, name,PhotoUrl,Birthdate from Contact WHERE Birthdate != null AND Birthdate = NEXT_N_DAYS:60 ORDER BY Birthdate ASC LIMIT 5 OFFSET 0
Birthdates are like this.
5/06/1992
5/04/1991
2/27/1995
3/03/1993
3/04/1993
OUTPUT Will Like
5/04/1991
5/06/1992
3/03/1993
3/04/1993
2/27/1995
I need sorted based on Month and day
2/27/1995
3/03/1993
3/04/1993
5/04/1991
5/06/1992
I hope you understand my requiremnent.
I think, your expected result provided by aggregate result.
I provide some sample code, just try it.
Thankyou for you quick and correct reply.
It's very helpfull for me.I used this query like this.