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
hamza akouayrihamza akouayri 

Valid SOQL query returning zero results in apex class but it return expected results in developer console

I have valid soql query returning zero results in apex class but it return expected results in developer console - FYI i have tried to running both context with sharing and without sharing  still no result. any idea 
@InvocableMethod(label='Get User info')
  public static List<userOutput> getUserLogedInInfo(List<userInput> inputParameters){
    
    List<userOutput> outputParameters = new List<userOutput>();
    userOutput outputParameter = new userOutput();
    String sEmail = inputParameters[0].sEmail;
    String sContact = null;
    String sUser = null;
    List <User> userList = [SELECT Id, FirstName, LastName, Email,ContactID FROM USER WHERE Email = :sEmail];
    System.debug('###### User####'+userList);
    
    if (userList.size()>0){
        sContact = userList[0].ContactId;
        System.debug('###### UserId####'+ userList[0].Id);
        List <AuthSession> auth = [SELECT Id, UsersId, IsCurrent FROM AuthSession WHERE IsCurrent = True AND UsersId = : userList[0].Id LIMIT 1];
        System.debug('###### auth####'+auth);        
        if (auth.size()>0){
            System.debug('i am here'+ outputParameter.sLogin);  
            outputParameter.sLogin = True;
        }
    }
    outputParameters.add(outputParameter);
    return outputParameters;
  }




 
AbhinavAbhinav (Salesforce Developers) 
Hi Hamza,

Have you checked suggestion for similar question?

https://salesforce.stackexchange.com/questions/214664/valid-soql-query-returning-zero-results-in-class-but-expected-results-in-develop

Thanks!
hamza akouayrihamza akouayri
Thanks Abhinav! but the link you suggest didn't help 
andres guevaraandres guevara
Try using
@isTest(SeeAllData=true)

in your test method