I think I'm going to have to find someone internal for this one, but posting to see if anyone has any ideas about this at all.

The Problem

We've got code in a managed package that's querying for tasks associated to a person account, and it's not finding a task that definitely exists.

This is the query straight from the debug logs but with some fields removed (there's a bit of funky spacing because it's auto-generated and I tend to err on the side of too much whitespace):

select WhatId, Id, CreatedDate from Task  where WhatId = '0014100000GcYdJAAV' and Outreach_Status__c != null  and Template_ID__c != null  and IsClosed = false order by ActivityDate desc

The next line of the logs is Rows:0.

Now if I take this same exact query, copied from the logs, and run it in the Query Editor in the dev console I see one record.

Next, if I take this same exact query, copied from the logs, and run it in Execute Anonymous in the dev console I see one record.

This record definitely exists, and I can see it in the UI too.

Things I've Checked

Sharing for tasks is private, the code being run enforces sharing. The user running this code is an admin, and owns the task. FLS is not the issue. Other code in the package running different queries against tasks (still with sharing) includes it in results.

The Question

Is there something I'm missing? Is this just yet another quirk of person accounts? If the query failed everywhere I wouldn't be so confused, but the fact that it works in other places has got me stumped.

  • Sounds silly, but I'm assuming you've tried these things via the LMA? Jun 11 '17 at 4:08
  • What is the context the query is running in - future, batch, synchronous, trigger, etc. not exactly your issue but I have see the exact same code (not exact as in your, as in the following example) executed in batch context throw non-selective errors yet executing from non batch 1 minute later and it works without issue. SF quirk that never figured out
    – Eric
    Jun 11 '17 at 4:13
  • @SebastianKessel No, logged in directly to the org. This is an extension package so can't actually get full logs even via the LMA.
    – Matt Lacey
    Jun 11 '17 at 4:20
  • @Eric This is all from an Apex remoting call. Doesn't seem to be a cache thing because even trying a few times in a few minutes doesn't get a result.
    – Matt Lacey
    Jun 11 '17 at 4:21
  • 1
    Be interesting to see if you added a button to the page and did the query in the controller not in a remoting context if it worked. But I gather it is managed so out may not want to do that, although a patch version would allow you to do so without affecting the main package. Unlikely it would work but it would rule it out.
    – Eric
    Jun 11 '17 at 4:28

Well, I should have known it would be me doing something dumb. Somewhere a couple of versions ago a few fields were added to the package, one of which was Outreach_Status__c.

The query has the following as part of the where clause:

and Outreach_Status__c != null

So of course, once the fields were added to the package, the code was actually querying the packaged field and not the regular custom field, despite the query in the logs showing it without the namespace.

As a workaround I've renamed the standard custom field so that it can be queried, so not ideal, but not the end of the world in this instance.


When you create manage package the custom field which is used in class are automatically added to your package and Namespace Prefix from org is added to that custom field API name(Lets say you created one field in Task XYZ__c and used in class which is added to managed package with namespace ABC..when you install your package in destination org the field created in Task object with API name ABC_XYZ__c ) when you try to fetch record in SOQL query with field with name XYZ__c it will not return any record, To get record used field with using combination of namespace and Api name like ABC_XYZ__c in your query

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.