+ Start a Discussion
PugetSoundJimPugetSoundJim 

Formula field not being calculated in SOQL queries?

I have a nightly Apex batch that is rather simple in my mind. For whatever reason, I am getting errors now several weeks after being implemented I would have thought been caught by now.  

The error I'm getting is "TRANSFER_REQUIRES_READ, The new owner must have read permission."  This error itself isn't a concern.  It makes complete sense.  

Basically the batch job is looking for records where the owners of ObjectA__c and ObjectB__c are different.  If they are, update ObjectA__c's Owner to ObjectB__c's.  The error being raised is a result of ObjectB__c's owner no longer being active within SFDC.

Looking at the records for the Users, ObjectA and ObjectB, I am finding no modifications in the past 24 hours that would have hit the criteria of the SOQL query.  Some of the records haven't been touched in several months.  This leads me to think that the formula field sometimes isn't being calculated during batch runs.  Has anyone seen this type of thing before?

SOQL

SELECT id, OwnerId, ObjectB__r.OwnerId FROM ObjectA__c WHERE
Ownership_Same__c = FALSE AND RecordType = Type1 AND ObjectB__c != NULL

Formula Field
Ownership_Same__c
If(OwnerId = ObjectB__r.OwnerId, TRUE, FALSE)
PriyaPriya (Salesforce Developers) 
Hi PugetSoundJim,

What is the relationship between the two objects?

Regards,
Ranjan
PugetSoundJimPugetSoundJim
Hi Ranjan - 

Object B is just a lookup on Object A.  

Thanks,
Jim