I am running a Dynamic SOQL query in my apex test code, and the LIMIT clause is not working. It does however seem to work when using it in the production code.
The Query is similar to below. I dynamically build up the where clause using some terms from a form.
string query = 'SELECT name, billingstreet, billingpostalcode, phone ';
query += 'FROM Account WHERE ';
query += '(name LIKE \'%limited%\' OR name LIKE \'%LIMITED%\') ';
query += 'LIMIT 500';
List<Account> results = Database.query(query);
System.assert(results.size() <= 500);
This can fail as the query seems to return well over 500 records in the test. The query does work however when using this in a visual force page.
Any thoughts?