+ Start a Discussion
textualtextual 

SOQL returning no results and giving me an error

So I've got a query where I'm trying to see if a user did something within the past 15 minutes

The query asks if theres a record where created date is greater than now - 15 minutes, limit 1

It works fine when theres results, but when theres no results, the query doesnt work

I was hoping I could ask to see if the result object is null, but instead I receive an error

 

Do i need to make a list for this just to see if its empty?

Im only looking to see if one record exists, so using a list seems to be overkill

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

Yeah, just use the size method and test to see if it is greater than zero.

 

boolean HasUpdates = boolean.valueOf([Select Id From Account Where CreatedDate > now - 15 Limit 1].size() > 0);

 

(the date part is pseudo-code).