+ Start a Discussion
mcrosbymcrosby 

Inconsistent SOQL results in VF page

I have created a custom Calendar page that is supposed to display event entries for the designated month/year for all users in my org (user count is about 30).  In my custom controller, I have the following SOQL:

Pseudo-Code:
Date sDate = {start date};
Date eDate = {end date};

events = [SELECT id, subject, description, location, activitydate, activitydatetime,
durationinminutes, isalldayevent, owner.name FROM Event WHERE activitydate >= :sDate AND activityDate <= :eDate ORDER BY activitydate, activitydatetime];

If I open the page as an Admin user, I retrieve all events for the date range for all users (as expected).  However, when logged in as a regular user and the page is first loaded, only the respective user's events are returned.

I would chalk this up as a permissions issue, but something odd happens when the user clicks on an apex:commandLink that changes the month in the controller.  When the link is clicked, all events for the date range for all users are returned.  It's almost as if the user needs to navigate to the next or previous month and then back to the current month in order for all events to show properly.

I have added System.debug statements to the code to verify that when the user initially opens the page, the event count reflects the number of events for that particular user for the current month.  However, when they navigate to a different month, the count reflects events for all users in the selected month.

Can someone explain why this would happen?


Ron HessRon Hess
look at the apex modifiers

with sharing

and

without sharing


this may give your apex controller a consistent list of events.
what you describe sounds a bit unexpected, should be one way or the other, but the same for each query.
mcrosbymcrosby
Thanks for trying to help, Ron.  I took a look at my code and the modifiers all appear to be correctly set.  I'll continue to play around with this to see if I can get consistent results.

*** UPDATE:

I found a way to get the results that I need, though I'm not sure why this is the case.  The initial query of Events was done in the constructor of the controller, using a private method specifically coded for that purpose.  Each subsequent call was done through a public method triggered by the apex:commandLink in the page.

To resolve the issue, I removed the call to the private method from within the constructor and instead relied on calling the method when the event list was retrieved (through a get method).  For whatever reason, this cleared up the inconsistent retrieval of records.  The constructor only retrieved events specific to the user, while the get method retrieved event records for all users (like I wanted).


Message Edited by mcrosby on 09-10-2008 11:38 AM
saharisahari

Hi

 

I am having similar requirement. I would like to have an interactive calender on my vf page. If a user clicks on any particular date of the calender, it shud display events that are being hosted on that selected date.

 

But I am not sure how to implement this calender events. It would be great if you can provide me the logic for this.

 

Thanks in Advance