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

SOQL in apex


I am new to Salesforce and apex and trying to retrieve an existing account which I think should  be a very simple thing.

But I do not get any rows back. Same query runs fine when I run it in Eclipse IDE on the schema.

 What can be the reason for not getting any rows back in apex code?


    public static Account retrieveAccount(){
    	Account testAct;
           String aId = '001V000000E1CPyIAN';
           List<Account> actList = new List<Account>();
           actList  = [select Id, Name from Account where Id=: aId];
           if (!actList.isEmpty()) {
                testAct = actList.get(0);   //get existing act
            System.debug('\n\n\n\n Acct = ' + testAct +'\n\n\n\n');
       }catch(QueryException ex){

       return testAct;





I think the hardcoded Id is not present in your org i.e. No account exist with this id in your organization .

Please check .

Please let me know if the issue is persist.

Yoganand GadekarYoganand Gadekar

definately, your harcoded id may not be present in your org hence it is not retriving any records.