You need to sign in to do that
Don't have an account?
Didn't understand relationship 'MyObj__c' in field path after creating Namespace Prefix
Hi All,
After creating a Namespace Prefix - a class would stop to compile with the following error:
Didn't understand relationship 'MyObj__c' in field path...
If I export the same unmanaged package to another ORG - it works just fine. If I rename the object name in the relationship query in the apex code to contain the prefix - the compilation error disappears as well.
This compiles:
[select ID, Name from MyObj__c LIMIT 1];
This won't compile:
[select ID, Name, (select ID from MyObj__c.Attachments) from MyObj__c LIMIT 1];
...but it will compile if I add the namespace prefix:
[select ID, Name, (select ID from mypkg__MyObj__c.Attachments) from MyObj__c LIMIT 1];
As I understood, creation of prefix does not supposed to affect existing apex code, it supposed to affect API calls and dynamic apex only. Is this right?
Can anyone suggest what might be wrong here? Or is there a problem with my ORG?
Thanks in advance,
Rolan
Solved the issue:
To make relationship queries compile on ORGs that contain a namespace prefix you should avoid writing the object name before the relationship name:
[select ID, Name, (select ID from Attachments) from MyObj__c LIMIT 1];
The following code will work only if namespace prefix is not defined:
[select ID, Name, (select ID from MyObj__c.Attachments) from MyObj__c LIMIT 1];
Rolan