You need to sign in to do that
Don't have an account?
Stephanie_Arce
SOQL relationship query
Hi, I'm trying to query on 3 objects with different relationships and need some help. The "base" of my query is a Receipt object, which has a lookup to a Gift object. The Gift object then has child records in an Allocation object. What I'd like to do is query Receipt data while listing the Allocations associated with the Gift on the receipt.
I can query the Receipt and Gift data like so:
SELECT Id, causeview__Gift__r.Id FROM causeview__Receipt__c
And query the Allocation child records from the gift:
SELECT Id, (SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c
But I'm not sure how to put the 2 together to get everything 1 query.
Thanks for any help!
I can query the Receipt and Gift data like so:
SELECT Id, causeview__Gift__r.Id FROM causeview__Receipt__c
And query the Allocation child records from the gift:
SELECT Id, (SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c
But I'm not sure how to put the 2 together to get everything 1 query.
Thanks for any help!
You will need to go from the causeview__Gift__c object, since both the causeview__Receipt__c and the causeview__Gift_Allocations__c are child objects of causeview__Gift__c object.
your query should look something like this:
Select Name, Id, (Select Id, Name From causeview__Receipts__r), (Select Id, Name From causeview__Gift_Allocations__r) From causeview__Gift__c
Hope this helps!
Best regards,
Martijn Schwärzer
All Answers
According to you Gift object is parent of both objects ( Receipt and Gift Allocation ).
So you can find a gift record with childs reocrd by below query
SELECT Id, (select id form relationshipname_with_alloction_object ),(SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c
Hope this helps !!
You will need to go from the causeview__Gift__c object, since both the causeview__Receipt__c and the causeview__Gift_Allocations__c are child objects of causeview__Gift__c object.
your query should look something like this:
Select Name, Id, (Select Id, Name From causeview__Receipts__r), (Select Id, Name From causeview__Gift_Allocations__r) From causeview__Gift__c
Hope this helps!
Best regards,
Martijn Schwärzer
lets try this once...
[Select Name, Id, (Select Id, Name From causeview__Receipts__r), (Select Id, Name From causeview__Gift_Allocations__r) From causeview__Gift__c]
SELECT Id, (select id from causeview__Receipts__r ),(SELECT Id FROM causeview__Gift_Allocations__r) FROM causeview__Gift__c