Just as important as ordering things, can be limiting things. Putting a LIMIT
on your SOQL statements let you specify the maximum number of records to return.
To grab any 4 Opportunities that are not closed we query like we normally would, and apply the LIMIT
at the end.
SELECT Name, StageName FROM Opportunity WHERE IsClosed = false LIMIT 4
Name | StageName |
---|---|
Dickenson Mobile Generators | Qualification |
United Oil Office Portable Generators | Negotiation/Review |
Grand Hotels Kitchen Generator | Id. Decision Makers |
United Oil Refinery Generators | Proposal/Price Quote |
Same is the case when we add order to things. We apply it all before we start to LIMIT
things down. To find a single opportunity in review with the highest probability we first order, and then limit.
SELECT Name, StageName, Probability FROM Opportunity WHERE StageName = 'Negotiation/Review' ORDER BY Probability DESC LIMIT 1
Name | StageName | Probability |
---|---|---|
United Oil Office Portable Generators | Negotiation/Review | 90 |