+ Start a Discussion

When i do soql in query editor it returns 2 record while same soql used in class not returning any record. What will be the issue?

Narender Singh(Nads)Narender Singh(Nads)
Are you using the keyword 'with sharing' while declaring your class?
If yes then, remove that and try.

Let me know if it helps!
Pradeep SinghPradeep Singh
Hi VJay,
When you are querying the data using query editor, it will return all the records according to the query. It runs in the system context. Here sharing settings are not taken into account.

When you query data using class where with sharing keyword is used, it runs in user context. It means if the OWD is private for the sObject for which the query is written/executed, it only returns the records whose owner is the current user and the records shared with the same user.

So in your case, you have 2 records for an SObject and OWD is private and no sharing is used with the user who is running the class(with sharing).