How to run entity field query in cron without getting undefined stdClass::$roles notice?
As you can see in the cron doc, cron runs as anonymous user so you have to run the query as admin user. 

In the EntityFieldQuery DO doc you can see examples, but essentially you just need to add the addMetaData code to the end  of your query:

 $q = $query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', $content_types, 'IN')
    -&gt;propertyCondition('status', 1)
    -&gt;propertyCondition('uid', $uid)
    -&gt;propertyCondition('type', $content_types, 'IN')
    -&gt;fieldCondition('field_something', 'value', $code, '=')
    // Run the query as user 1.
    -&gt;addMetaData('account', user_load(1));