You need to sign in to do that
Don't have an account?
Rajnish Bishnoi 13
Not getting record in query in Test class with a third reference
Hi ,
I am not able to get record in query in test class if i am providing the 3rd reference filter in query.
But if i am not providing the filter in query then i am able to get the record and i can access thet 3rd reference data also.
Not able to understand what is the issue with query filter.... please help.
My query is on User and i am providing filter on Custom object which is related to user through Contact Object.
Thanks,
Rajnish
I am not able to get record in query in test class if i am providing the 3rd reference filter in query.
But if i am not providing the filter in query then i am able to get the record and i can access thet 3rd reference data also.
Not able to understand what is the issue with query filter.... please help.
My query is on User and i am providing filter on Custom object which is related to user through Contact Object.
Thanks,
Rajnish
NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.
List<User> usr=new List<User>([Select Id, Employee_Type__c, Employment_Status__c,email,Contact.COS_LOS_Users__c, Contact.COS_Hostid_Users__c, Contact.Reference_Key__r.Name,Contact.Reference_Key__r.End_Date__c from User where ((Employee_Type__c!='Employee' OR Employment_Status__c!='Available') and Contact.COS_LOS_Users__c=true AND Contact.Reference_Key__c!=null AND Contact.Reference_Key__r.Name!=null)]);
The bold condition in the query creating the problem. If i am using this Contact.Reference_Key__r.Name!=null filter in query then i am getting 0 record. But without this condition i am getting the record, and with that record i am able to access usr[0].Contact.Reference_Key__r.Name.
So i am unable to understand that why the filter in query not providing the record.
If you include line number 17 you get no results returned. But if you remove line 17 you get a result back that has the Contact.Reference_Key__r.Name populated? Are you creating the User record during your test?
i am getting the result after removing the line 17 and getting the reference key name as well.
Yes i am creating the User record during test.