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

How to get data from a Parent to child relationship query?
Hi, in this case I´d like to know 2 things. According to the next query, I need to establish the list of campaigns that are NOT related to a custom object where we have a search field related to campaign object. Their relationship is something like this:
Campaign - one to many = MyCustomObject__c
Here is the query:
Code:Select c.Id, c.Name, c.CustomFieldA1__c, c.CustomFieldA2__c, (Select CustomFieldB__c From MyCustomObject__r) from Campaign c where c.RecordTypeId=:MyOwnRecordType
That query returns ALL CustomFieldB__c values asociated to every campaign, but what I really need is to get ONLY, the list of campaign that are not included in the child object. something like a LEFT OUTER JOIN.
And the second question is according to the given query, how could read the value of CustomFieldB__c by using ApexCode?
Regards,
WILMER
I would do this in a two-step process. First, query all recs in your custom object, put the Campaign Id's returned from this into an List or Set. Then query the campaign object with ' Id NOT IN :mySet '.
Of course, depending on your data set size, this could run you afoul of governor limits.
Question 2:
with the query you have, the set of related custom objects would be a List contained in the Campaign objects returned.
So you could do something like
for ( thisCampaign : queryResults ) {
MyCustomObject__c [] thisCampaignsCustomObj = thisCampaign.MyCustomObject__r;
}
HTH
Great ideas sparky. I'll follow your directions and will let you know the result.
Thanks a lot.
Wilmer