+ Start a Discussion

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.






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?


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.


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. 


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