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
Sam D.Sam D. 

Event SOQL query empty (in trigger only) when its a SHARED ACTIVITY

Strange problem here. I have a trigger that does a simple SOQL query to retrieve an Event by its ID, e.g.:
List<sObject> theRecords = [select Id from Event where id = '00UC000000Pyy6c'];
It usually works with no problems. However when multiple contacts are added to the event and it becomes a shared activity, suddenly the query comes up empty when run in the trigger, even under a sysadmin profile.  Yet the same exact query is successful when run in SoqlXplorer, and when the code is executed using anonymous apex.

Any ideas for what might be going on? Does changing the Event to a shared activity with multiple contacts somehow change its ability to be queried via its ID?  

Thanks.
Best Answer chosen by Sam D.
Dominic Blythe 18Dominic Blythe 18
Hi Sam,

Where is the query being run? In Apex code?

If so, you need to check the API version of code unit (class or trigger) that is running the query. Shared Activities are quite new, and they're invisible to older versions of the API. So adding multiple contacts to an Event can make it disappear from the code's view.

The earliest version of the API that can see shared activities is 26. So you need to make sure your code is API 26 or later.

You can view and change the API version of classes and triggers in the Salesforce UI. If you're using eclipse you can edit the metadata XML directly.

Dominic

All Answers

Dominic Blythe 18Dominic Blythe 18
Hi Sam,

Where is the query being run? In Apex code?

If so, you need to check the API version of code unit (class or trigger) that is running the query. Shared Activities are quite new, and they're invisible to older versions of the API. So adding multiple contacts to an Event can make it disappear from the code's view.

The earliest version of the API that can see shared activities is 26. So you need to make sure your code is API 26 or later.

You can view and change the API version of classes and triggers in the Salesforce UI. If you're using eclipse you can edit the metadata XML directly.

Dominic
This was selected as the best answer
Sam D.Sam D.
Dominic for President!  That did the trick, thanks.

Btw just curious, when you upgrade the API, do you usually upgrade to the most recent version, or the minimum version that solves your issue (in this case 26)?
Dominic Blythe 18Dominic Blythe 18
I'd say in most cases, if you can see all the code in front of you and it's clearly not complex, you're probably fine to up the API version to the current version. SFDC will tell you if it spots anything amiss, and if it doesn't, then you've got 100% test coverage with system.assert() to spot regression, right?
Sam D.Sam D.
Why yes, of course!  

...probably...