+ Start a Discussion
OlbrestOlbrest 

How to get quantity of records after select from database ?

How to get quantity of records after select from database ?

I have such code. What I must set instead '????' ?

Code:
public void test3() {

Opportunity[] opp = [select ownerid from Opportunity];
????

}

 
Thank you.
kyleRochekyleRoche
try something close to [select count() from opportunity where ownerid = :myOwnerId]

JimRaeJimRae
If you are selecting into an array as you show in your sample, you can use the size method to see how many results were returned.

Code:
public void test3() {

Opportunity[] opp = [select ownerid from Opportunity];

Integer oppcount = opp.size();
System.debug('Retrieved '+oppcount+' Opportunity records');

}

 

OlbrestOlbrest
Thank you.
It works !