0

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?

OR

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 ?

Thanks

3

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.

1
  • I too have a leaning towards the 2 queries. There are probably 10 queries other than these 2 in that VF page. The number of records are not too huge maybe just a few hundreds
    – Prady
    Sep 13 '12 at 10:38
1

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. (https://sites.secure.force.com/success/ideaView?id=08730000000Br7TAAS)

5
  • i might not be able to use list.size() method to get the count. i would have to loop through the list to get the count for given date as well as for the next 7 days
    – Prady
    Sep 13 '12 at 10:36
  • ok.. then it depends on the size of the result set.. If your result set is much larger, then looping the list may hit the limits..
    – Priyanka
    Sep 13 '12 at 10:44
  • Are you going to fetch the details and show up in the page or you are going to put count(id) query to get the count..
    – Priyanka
    Sep 13 '12 at 10:46
  • I dont need the details, just the count.. i need a count of records for todays date for each contact and another count for next 7 days
    – Prady
    Sep 13 '12 at 10:51
  • ok fine then.. If this is the case then write 2 queries as you said above(1st option). Don't use the query select count(id) from object__c. Instead write the query as "select id from object__c where bookingdate = givendate" and use list.size() to get the count..
    – Priyanka
    Sep 13 '12 at 10:54

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.