Reply
Visitor
bosuch
Posts: 2
0

Really basic question

I've literally been using Salesforce for about 30 minutes now, so this may be a pretty basic question. I'm trying to use an Apex class to retrieve a List of Accounts, like this:

 

List<Account> lstAccount  = [select id, name from Account];
System.debug('*** Number of Accounts: ' + lstAccount.size() );

 

But I'm never able to retrieve anything. I have a single account set up. Suggestions? Thanks.

Super Contributor
sfdcfox
Posts: 4,041
0

Re: Really basic question

Nothing looks wrong so far. Maybe it's elsewhere? Could you post more code?

~ sfdcfox ~


I am a sandwich. That is all.

Visitor
bosuch
Posts: 2
0

Re: Really basic question

Nothing more to post, that's the full extent of the method. If I don't use the list and just try something like:

 

Account a = [select id, name from Account LIMIT 1 ];

 

...then I get the dreaded "List has no rows for assignment to SObject".

Super Contributor
sfdcfox
Posts: 4,041
0

Re: Really basic question

1) Is this a "test method"? If so, you need to make sure you create at least one account within the test method, or use "@isTest(SeeAllData=true)".

 

2) Is this an empty database? Make sure you've created at least one record.

 

3) Are you testing as a non-admin? Make sure sharing allows access (Setup > security > Sharing)

~ sfdcfox ~


I am a sandwich. That is all.

Trusted Contributor
vishal@force
Posts: 429
0

Re: Really basic question

yes, the error suggests you do not have any Account in your org. Developer editions have a few Accounts by default, FYI.

 

Or maybe the user who's running this code does not have access to Accounts.

Vishal, Certified Developer and Administrator
Kudos a post if it helps, mark it as solution if it solves.
http://exploretheforce.blogspot.in
Trusted Contributor
successforce
Posts: 240
0

Re: Really basic question

It is more likely that you do not have access to the account record. Try creating a few more, and run the query again.

 

- Anup

Anup Jadhav | twitter: @anup | anupjadhav.com