function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Strange APEX SOQL permission issue!

I've an SOQL which queries an object and its associated Account & Contact values like this:


CustomObject__c co = [Select ID, Account__c, Contact__c, OwnerID From  CustomObject__c Where ID =: idvar];


Now, this works fine in my Development org. I can read the record in above query. But in user org I could not do so. Just so you know, I am "not" using "with sharing" keyword in my Apex Class. So automatic sharing does not apply to the SOQL results, right?


The only difference I can note in the 2 orgs is: User has Record Types created. DO anyone know if RecordType can effect user read permissions?


I've verified "Sharing Settings" too, the values are identical in both orgs, and also user is using same profile settings and Same Group as I'm using in my Dev org.



Please help, this is really bugging me out, I don't know what is making the record invisible in soql ... :(


It seems possible that there's a different issue causing your query to return no results. For example, what is the value of "idvar"? If you post more of your code, we may be able to point out some troubleshooting steps.




If you are thinking that really this query is failing in production, you can run this query from system log and find out exactly whether do you have the records with this criteria or not. There might be small mistake which you might have overlooked :)



String idvar = ApexPages.currentPage().getParameters().get('idvar');
if (idvar != null && idvar != '') {
	Matter__c[] m = [Select ID, Account__c, Contact__c, OwnerId From Matter__c Where Id =: idvar];
	if (m.size() > 0) {
		billrecord.Account__c = m[0].Account__c;
		billrecord.Contact__c = m[0].Contact__c;
		billrecord.Matter__c = m[0].ID;


This is my query. The query runs and Return record in System Log console of sfdc. And "idvar" has the Value in QueryString URL. I'm seeing it in browser URL.



I'm not sure if this will help you but, I once learned somewhere that null values should be tested for as such:


if(null ! = idVar)


rather than:


if(idVar != null)




Try removing idvar != '' condition.



kandasmu wrote:

Try removing idvar != '' condition.

I have already verified this via system log, "idvar" is carrying the record id value correctly. I've placed system.debug() statement inside my if (idvar != null) check and that debug statement got executed correctly.



if you are getting record in system log, may be incorrect id is passed in query string, may be a space added to it, more may bes.... :smileyhappy: good luck