You need to sign in to do that
Don't have an account?

System.QueryException: object is not accessible in query due to package restrictions
I have run into this error message when trying to use dynamic SOQL for the first time. I am running the query in a managed package, but the object I am working with is in the same managed package, the package api is unrestricted, and my profile is system admin with full rights. Can anyone think of any other settings that would be causing restricted access?
-David
-David
Sample trigger:
trigger Contact_Test on Contact ( before update )
{
System.debug( trigger.new[0].get( 'FirstName' ) );
}
This appears to be a Dynamic Apex + Packaging bug.
My package can access the objects and fields in question just fine if I access them via a strongly typed object instead of Dynamic Apex.
This works:
System.debug( Contact.FirstName );
This gives the "not accessible" error message:
System.debug( sobjectVariable.get( 'FirstName' ) );
From a permissions standpoint, both should have the exact same limitation within my package. In my case, I'm simply converting my existing working package from strongly-typed code to heavy use of dynamic apex.
System.SObjectException: Contact.FirstName not accessible due to package restrictions
It happens during field access, not during a dynamic SOQL statement.
System.QueryException: PrefixXXX_OBJECTXXXX__c is not accessible in query due to package restrictions
If there any formal bug o planto fix this ? or some way to avoid this issue until then?
Any ideas?
Any Idea when salesforce is fixing this?
It would be greate that guys at salesforce.com write a post on the offical blog, of what things can not be packaged on winter09.
Best regards.
I think I figured out a workaround for this. Enable restricted API access for your package and give yourself read access to the standard object you were trying to access via dynamic apex from your package. For instance, I was trying to dynamically query Case from my pkg and was getting errors in my test code and after restricting my pkg's api access and checking off read on Case it works just fine.
It makes no sense because an unrestricted pkg should have more access then a restricted pkg so I still think the fact that you have to explicitly grant access is a little bazar.
Anyway, hopefully this helps some of you out.
Regards,
Mike
But somehow now my code is not getting the Custom Fields. This is strange. I am getting both Standard and Custom fields in my dev Org but when I package this - I get only standard fields.
I am using -
mapSObjectField_Contact = Schema.SObjectType.Contact.fields.getMap();
Any help here will be great!
Thanks,
Rakesh Aggarwal
Will this be fixed in the Spring 09 release and we can use Dynamic SOQL in a managed package ?
I read that now bind variables are supported in Dynamic SOQL, maybe they worked on this as well.
Can someone from Salesforce please respond.
Thanks.