Development questions
Write a SOQL query to find the 2nd Highest Amount among all Opportunities (ORDER BY Amount DESC NULLS LAST LIMIT 1 OFFSET 1).
Sort descending, skip the first row, and take one.
soql
SELECT Id, Name, Amount FROM Opportunity
WHERE Amount != null
ORDER BY Amount DESC NULLS LAST
LIMIT 1 OFFSET 1
This returns the record with the 2nd highest Amount (ties return the next row, not the next distinct value; for distinct values group by Amount).
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?