An error occurred when I run this SOQL query.
SELECT long_number FROM some_table WHERE long_number <= 1638369480000
Error message:
MALFORMED_QUERY: some_table WHERE long_number <= 1638369480000
ERROR at Row:1:Column:57 For input string: "1638369480000"
I solved the error by adding ".0" to the end of long_number
.
SELECT Timestamp__c FROM IoTRM_FacilityLog__c WHERE Timestamp__c <= 1638369480000.0
Can anyone help me understand why adding ".0" can solve this error?
Best Answer
SOQL uses 32-bit signed integers, meaning the maximum integer value is 2,147,483,647.
SOQL doesn't understand long literals (e.g. something like
1638369480000L
). It'll complain about the 'L', and if you leave it out it'll try to treat it like an int.By adding
.0
to the number literal, SOQL treats it as aDecimal
, which can handle literals larger than 32 bits.+edit:
Though if you're really trying to use a timestamp here, using a
Datetime
field instead of aDecimal
would probably be a better decision.You can get a Long timestamp (since unix epoch, 1970-01-01T00:00:00Z) by using the
getTime()
method, and turn a timestamp into a Datetime usingnewInstance()
.