I have a problem with the Database.query. Its not returning the data to the Apex class, But when I am using the query editor, its showing the correct data. My query is

List<CM_Group__c> e = Database.query('SELECT 
CM_Skill_Level__c,CM_Start_Date__c,Name FROM CM_Employee__c where 
CM_Start_Date__c != null');

When I am checking with the debug logs, it is showing empty. But when I am using query editor, it is showing the below result:

enter image description here

  • 4
    What is the Org-Wide Default for CM_Employee__c? Who is the running user for Database.query()? Is the enclosing class declared with sharing or without sharing? – David Reed Jan 2 '19 at 15:03
  • this is my class declaration . global class EMP_EmployeeAudit{ } – Salmaan C Jan 2 '19 at 15:05
  • can you make it global without sharing class EMP_EmployeeAudit – Pranay Jaiswal Jan 2 '19 at 15:08
  • 1
    If you have not already, I would encourage you to complete security-focused modules on Trailhead, such as this one and this one, along with the sharing Apex documentation. – David Reed Jan 2 '19 at 15:28
  • 2
    just to be sure - you see this behavior in anonymous apex? or in a testmethod. If a testmethod, unless you mock the data, it will return nothing – cropredy Jan 3 '19 at 1:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.