2

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?

6

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 a Decimal, 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 a Decimal 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 using newInstance().

1
  • @Dreck Thanks for your help. The reason I saved the datetime as a number is because that it seems datetime does not keep milliseconds which is a must in my current project.
    – Xin
    Dec 6 '21 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.