function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ministe_2003ministe_2003 

Shared Activities not returned in SOQL query

Hi all,

I've written a custom tab on which users can view their events but ever since the introduction of Shared Activities I've had a problem in that any event which has more than one contact assigned to it, does not appear in the query results.  I'm only querying the Event object, are shared activities stored under some different object?  I assumed they would still be Events but with related EventRelation objects storing the multiple contacts.

 

Note that strangely, the correct number of results are returned if I run the exact same query through the developer console but when run through the apex/VF I only get results containing a single contact.

 

Thanks

Steven

Best Answer chosen by Admin (Salesforce Developers) 
ministe_2003ministe_2003

Ah mystery solved.  I changed the API version of the class and VF page from 25 to 27 and now all results are returned, with absolutely no changes required to the code.

All Answers

Vinit_KumarVinit_Kumar

What is the query you are running to get the results.

ministe_2003ministe_2003

I have a couple which are all basically the same, just that some are aggregations and some are direct queries.  Here's an example:

 

totalRecs = [SELECT count() FROM Event WHERE OwnerId = :loggedOnUser AND RecordTypeId = :cvRecTypeId AND isDeleted = false ALL ROWS];

 

loggedOnUser is a pre-set variable which simply contains the currently logged on user's Id, cvRecTypeId is a record type Id, populated through a Describe call.  If I run this through the developer console I get the correct number of events but when this query is run in apex called from the VF page, the number is smaller and ignores any records with more than one contact assigned.

 

There are no visibility issues as I'm obviously running through the admin profile

Vinit_KumarVinit_Kumar

When shared Activities is enabled you should be querying on EventRelation object and filter on RelatioId field on it to get the correct results.Please go through the below link for the same :-

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_eventattendee.htm

ministe_2003ministe_2003

I can understand the EventRelation object giving me the related contacts, but none of this explains why the event itself is being excluded from the SOQL results when run inside a VF page, but is being returned when the query run in developer console.  I should also add, the event is also returned when running the query through the Eclipse Schema explorer.

ministe_2003ministe_2003

Ah mystery solved.  I changed the API version of the class and VF page from 25 to 27 and now all results are returned, with absolutely no changes required to the code.

This was selected as the best answer
Vinit_KumarVinit_Kumar

EventRelation object is only available in API 26.0 onwards :)

ministe_2003ministe_2003

Again, I'm not using EventRelation, I'm just using Event.  I'm not particularly interested in the contacts that are assigned I just need details from the event itself which I couldn't do in api 25 but can in 27 for some reason, even though its all simply Event records I'm querying.

Vinit_KumarVinit_Kumar

Shared activities is also available after API version 26.0 .

ministe_2003ministe_2003

There's no explaination for that though because its the same object.  I can't find anything in the docs which says if you query events, you won't get shared ones unless you're on API 26 or above

Vinit_KumarVinit_Kumar

Please go through the below link which confirms that this feature was delivered in Winter'13 which is API version 26.0

 

 

https://success.salesforce.com/ideaView?id=08730000000BrrGAAS

ministe_2003ministe_2003

Again, nowhere does it say shared activities will be stored as events but not returned in event queries.

PaolaPaola

Hi,

 

I am having the exact same problem with a trigger that does not query all EventRelation on a Event, but when you query the same list in the console the whole list is selected. The trigger is upgraded to the version 27.

 

Does anyone have the same issue still?

 

Thank you

ministe_2003ministe_2003

I wasn't querying EventRelation, only Event and that was fixed by upgrading to 27.  I wasn't interested in the contacts assigned (hence not querying EventRelation) and only wanted to retreive information about the event itself.  So if your issue is related to querying EventRelation instead of Event, it might be a different issue.