7

I've just encountered a weird behaviour of SOQL and I wonder if it's a bug or maybe some feature I do not understand: looks like the compiler lets you add an incorrect LIMIT clause - LIMIT1 for example - and does not indicate any issues with that. It also doesn't limit the query actually.

Following queries: SELECT Id FROM User LIMIT1, SELECT Id FROM User LIMIT43 both result in below:

1646 SOQL results

Any ideas if there's a reason behind this behaviour?


EDIT: turns out the compiler ignores any word added to the end of the query, e.g. SELECT Id FROM User FSAETGSRFESA

Random word SOQL 1646 results

4
  • Have you tried the LIMIT 1? Give one space in between the LIMIT keyword and the numberOfRows. If you have run the query in developer console then first remove the result and try the LIMT<Space>numberOfRows. SELECT Id FROM User LIMIT 1 Commented Sep 4, 2023 at 8:39
  • @TusharJadav I am aware of how it should look like :) I'm just wondering if that's a Salesforce bug or is there something else behind the behaviour Commented Sep 4, 2023 at 8:41
  • 2
    So basically any single word in the end of the query is ignored (apart from ones from official specs)?
    – kurunve
    Commented Sep 4, 2023 at 9:11
  • @kurunve oh, you are actually right. That's still a bit surprising :) Commented Sep 4, 2023 at 9:39

1 Answer 1

13

This will be the Alias Notation for objects. E.g.

SELECT count()
FROM Contact c, c.Account a
WHERE a.name = 'MyriadPubs'

In your case LIMIT43 is actually an alias for User. So you will find this works as well:

Select LIMIT43.Id From User LIMIT43
1
  • 2
    I think the surprise on my part was that the object notation works on non-aggregate queries. The example query uses an aggregation, and we all know that you can't use field aliases in non-aggregated queries, so the natural assumption was that you couldn't use object aliases, either.
    – sfdcfox
    Commented Sep 4, 2023 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .