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
dev_jhdev_jh 

Simple question about SOQL statement

Hi all,

I am not very familiar with SOQL yet. I want a query that returns the Maximum value for an autonumber field on a custom object. On ANSI SQL I would use MAX but it doesn´t seem to be available in SOQL. I can see that the below statement provides me with the result I want but not sure if it is optimal (it doesn´t look great):

SELECT Name FROM X__c ORDER BY Name DESC LIMIT 1

Any suggestions?

Thanks,

J
scriptagentscriptagent

Hi dev_jh,

I think, right now there are no better options to get the MAX value, because there are no aggregate functions available.

Best, Peter