You need to sign in to do that
Don't have an account?
RoyGilad
Querying Master Record in test class vs. in DevConsole
Hi,
We have a Test class the query a Master record deatils and get nulls only in the test class, in "real" run (via annanumence code run) - it does get values.
Any idea?
Code:
We have a Test class the query a Master record deatils and get nulls only in the test class, in "real" run (via annanumence code run) - it does get values.
Any idea?
Code:
Success__c suc = (Success__c)SmartFactory.createSObject('Success__c'); suc.Account__c=acc.Id; suc.Opportunity__c=opp.Id; User successOwner=[select Id,LastName,IsActive from User where UserRole.Name like '%CSM%' and IsActive=true limit 1]; system.debug('Tal Carmi emvcsmic successOwner: '+successOwner); suc.OwnerId=successOwner.Id; insert suc; suc=[select Id,OwnerId,Owner.LastName,Owner.IsActive from Success__c where Id=:suc.Id]; system.assertEquals(successOwner.Id,suc.OwnerId); system.debug('Tal Carmi emvcsmic suc: '+suc); system.debug('Tal Carmi emvcsmic suc.OwnerId: '+suc.OwnerId); system.debug('Tal Carmi emvcsmic suc.Owner.LastName: '+suc.Owner.LastName); system.debug('Tal Carmi emvcsmic suc.Owner.IsActive: '+suc.Owner.IsActive);Log (in test class run):
Have you used this annotaion?If you want to access your org data in test class use this annotation.
Like this in class.
However its not best practice.Insert some test data in the test class and then query.
For more info:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_seealldata_using.htm
If it helps make it as best answer.
Thanks.
I suggest avoiding "SeeAllData=true".
Verify sharing settings, any trigger exception (the usual stuffs) and then open a case with salesforce.