1

I have a very simple query on Tasks that get Tasks created by a user. If I run the query in the Dev Console I get 4 rows (as admin). The same query in an apex method (as the user/owner), I get 1 row only.

So far I've tried: - Checking the permission set for the user, to ensure it has all access to the Task object - Added the ALL ROWS to the Apex query - This is on a dev org with default settings

Select Id,
                             ActivityDate, 
                             Priority, 
                             OwnerId, 
                             Status, 
                             Subject, 
                             Description, 
                             whatid 
from Task 
where CreatedById in (select id from user where name='Linda Charles')
and IsClosed=false

Why might the queries have different results?

2
  • What if you change the filter to CreatedBy.Name = '...'?
    – Adrian Larson
    Sep 21, 2017 at 21:48
  • Same result, i've even add the actual static ID of user in quotes to check Sep 21, 2017 at 21:50

1 Answer 1

1

Tasks & Events' visibility is "controlled by parent" record. Check sharing. Is there any chance that the user you're running it with can't see the Account X -> he can't see Account X's tasks? If the task you see as admin is for record X (be it std or custom object) - see if navigating to that object's URL throws "Insufficient privileges" for your end user... Alternatively you could edit the apex method's class to make it run without sharing and see if it makes any difference.

Normally another obscure thing I'd suggest is to simplify the query, make it run based on user's ID. Comments say you've already tried it. In extreme cases end users with locale set to say Chinese or Hungarian will prefer "Lastname Firstname" order and then query for "Linda Charles" might return 0 results or a completely different user ;)

4
  • Thanks, I did a simple test class with RunAs (as the user), and it's also returning only 1 row. So it very could be the parent record you mention. To confirm, the parent is defined by the WhatId/WhoId right? Sep 21, 2017 at 22:02
  • Correct :) You should also be able to click [Sharing] button on the Task (if it' not there, add it to page layout). It depends on manual sharing, Event invitees... but the core of it is the parent record, WhatId/WhoId.
    – eyescream
    Sep 21, 2017 at 22:05
  • Thanks!!! it seems those records not showing up had null for WhatId/WhoId so that was it. Sep 21, 2017 at 22:09
  • Nice. Sounds like they're user's private Tasks. No amount of sharing can make visible (to non-admins of course) Contacts or Opportunities that don't have Account specified. I guess Tasks work in similar way.
    – eyescream
    Sep 21, 2017 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .