Salesforce Fact #419 | Nth highest using SOQL

Suppose we have a use case where we need to find the Nth highest value of a number field in an Object. We can get the same using SOQL.

In this example,  we are getting the 2nd highest value of NumberOfEmployees in Account object. Here is the SOQL:

SELECT NumberOfEmployees FROM Account GROUP BY NumberOfEmployees ORDER BY NumberOfEmployees DESC NULLS LAST LIMIT 1 OFFSET 1. Here OFFSET=N-1.

Comments

Popular posts from this blog

Salesforce Fact #192 | Call batch apex from flow

Salesforce Fact #457 | Get current user role name in flow