You need to sign in to do that
Don't have an account?
Naveed Anwar
SOQL for multilevel relationships for custom objects
Hi,
I am trying to build a query for multilevel relations.
I have 3 Objects that are involved in the query.
Item, PackageItem and Package.
Item linked to PackageItem through ItemCode.
PackageItem linked to Package through PackageCode.
What i want is to extract "PackageCode". So far i tried the following query.
Select Name, (Select Name From PackageItems__r) From Item__c Where ProgramID__c != null
I cannot find a way to include Package object in the query.
Please help
Thanks!
Hi,
I got the solution.
When i expanded the Package__c reference field in custom object PackageItems__c using "sforce explorer" i found the Package__r relation.
Select Name, (Select Name, Package__r.Name From PackageItems__r)
From Item__c Where ProgramID__c != null
Thanks for your help.
All Answers
From the API documentation on relationships:
You can create a dummy formula column on package item for package name [say 'mypkgname'] and use it as a column from packageitem__r as
Select Name, PackageItems__r.name, PackageItems__r.mypkgname From Item__c Where ProgramID__c != null
Hi,
When i try to run the following query:
Select Name, PackageItems__r.Name From Item__c Where ProgramID__c != null
i got the error: Didn't understand relationship PackageItems__r in field path ......
The query that i mentioned in my first post runs fine.
Can you give me some workaround for the above error?
Thanks!
Hi,
I got the solution.
When i expanded the Package__c reference field in custom object PackageItems__c using "sforce explorer" i found the Package__r relation.
Select Name, (Select Name, Package__r.Name From PackageItems__r)
From Item__c Where ProgramID__c != null
Thanks for your help.