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
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 !