3

We have a try/catch block around the line doing the query, but we still get this exception mailed to us on some SOSL queries:

List<List<SObject>> ret, queryResult;
try {         
     queryResult = search.query('FIND \'' + String.escapeSingleQuotes(searchTerm) + 
     '\' IN ' + searchFields + ' RETURNING ' + returningClause);       
} catch (Exception e) {         
     return null;       
}

caused by:

System.UnexpectedException: Search unavailable

Is there a way to catch this Exception and retry, or handle it more gracefully?

  • 1
    What exception type are you catching in your catch? What code is calling this query when this exception is raised? Are you attempting to use SOSL on an object that does not support it? Some more details and code examples might help here. – pchittum Aug 27 '14 at 23:39
  • List<List<SObject>> ret, queryResult; try { queryResult = search.query('FIND \'' + String.escapeSingleQuotes(searchTerm) + '\' IN ' + searchFields + ' RETURNING ' + returningClause); } catch (Exception e) { return null; } – Dale Chen Aug 27 '14 at 23:44
  • In this case, we are searching Lead, Contact, or Account objects and the searchfields and returning clause are constants that list the fields we want. – Dale Chen Aug 27 '14 at 23:46
2

As far as I know, there are three types of exceptions that you cannot catch: UnknownException, UnexpectedException, and LimitException. The first two are situations that your code can't handle, since they are system problems, and the latter you're not allowed to handle.

I'd recommend reporting this exception to support, since your query shouldn't be failing this way. Only QueryException should be possible in normal situations.

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.