Find your content:

Search form

You are here

Get the count of no of booking made by contact for given date and for next seven days after given date


I have a custom object called booking which has alll the bookings made by contacts. I need to have a VF page to get all the bookings made by all the contacts with a specific recordtype and show the no of bookings made by each contact for a given date in search criteria. We would also need to show the booking made for next 7 days too.

The question that i have is

Should i have one query written to get the count for given date and one for getting the count for the next 7 days?


Write a single query to get all the records for the bookingdate >= givendate and bookingdate <= givendate +7 and then loop through the list to get the count

Which approach would be best or is there a better way other than the two i mentioned ?


Attribution to: Prady

Possible Suggestion/Solution #1

I think this is largely academic, because unless you're dealing with a seriously large number of bookings performance isn't going to be a worry on this platform (code execution and database hits are not the slow parts of interactions), and limits shouldn't bother you either.

I'd argue that the two query approach is preferable though, since that will only contribute two counts to your query limit, whereas counting them up could add a considerable volume to your number of statements executed.

Attribution to: Matt Lacey

Possible Suggestion/Solution #2

I suggest to follow the first approach(one query written to get the count for given date and one for getting the count for the next 7 days) and use list.size() to get the count size.

If you use count query then value returned in the query will be added up to the number of SOQL rows retrieved. (

Attribution to: Priyanka
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content