check for null records

Salesforce sometimes returns null records (e.g. when using retrieve()
with ids that don't find anything), and we need to avoid the null
pointer exception.