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
MikeGillMikeGill 

Formula field not being returned in execute anonymous apex

Hi All,

 

Strange one. I have a query string which I am filtering using a formula field, this works correct if I just execute the query. If I try and execute the query string using Execute anonymous I don't get any results back from the query.

 

String qs = 'select Id, Subject, Description, Legacy_History_Id__c, Legacy_Id__c  from Task where Legacy_Id__c = \'218bc9a3bOFEP\'';

List<Task> results = Database.query(qs);
System.debug('Results size = '+results.size());

 

I'm expecting results size to be 1.

 

Any ideas.

 

Cheers,

 

Mike

bob_buzzardbob_buzzard

The only thing I can think of is that execute anonymous runs as the currenly logged in user, so is it a permission/record visibility issue?

MikeGillMikeGill

I'm using "SOQL Xplorer" on Mac BTW.

 

I am testing the SOQL in the same tool using same login credentials, for which I can results are returned. Hence why I am puzzled.

bob_buzzardbob_buzzard

Have you checked whether you can view the record in question through the UI, including the external id field? I'd expect that to behave the same as the execute anonymous. 

MikeGillMikeGill

Yep can access via the UI - very strange isn't it