function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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:
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?
Question 1:
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;



Great ideas sparky. I'll follow your directions and will let you know the result.

Thanks a lot.


We have 2 issues where we are seeking to develop with an Apex Webmethod and some script:
1-Custom Button from Area VP's and Regional VP's to push out a series of 2 or 3 tasks each week or month to the field sales.  There would be thousands of tasks sent each salesperson either by the Area VPs or the Regional VPs.
Can you provide an idea on the Webmethod and scripting to accomplish this in Apex?
2-Execs also want a daily automatic upload that provides the quantity of current Active Accounts ie.customers and their types, 6 types.  Again this will be in the 1000's so it will need tobe done on Apex.
Can you provide an idea on the Webmethod and scripting to accomplish this in Apex?
What are the governors in SFDC on records in the GUI and on the Server?