Development questions
Write a SOQL query to find the Nth Highest Salary on an Employee__c object.
Use ORDER BY ... DESC LIMIT 1 OFFSET N-1. For the 3rd highest salary:
soql
SELECT Id, Name, Salary__c FROM Employee__c
WHERE Salary__c != null
ORDER BY Salary__c DESC
LIMIT 1 OFFSET 2
In Apex, use a variable: LIMIT 1 OFFSET :n where n = N - 1. OFFSET max is 2,000. For distinct salaries, first group by Salary__c (aggregate) then apply the offset.
soqlscenariooffset
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?