You need to sign in to do that
Don't have an account?
Jared Rosenberg
Referencing sObject within another sObject
Good afternoon, folks.
I'm in the process of trying to consolidate the SOQL calls within a trigger of a particularly difficult sObject. This sObject has enough code running on it that we're pretty regularly hitting the 101 error--so it's time to clean up and bulkify where possible.
I've run the following to fill a map with an sobject, and the children of that sobject. Let's assume for the moment that Service_Order_Line is a child of Service_Order with a many-to-one relationship, and I've filtered this down so I'm only getting one Service_Order and maybe 5 or 10 Service_Order_Lines:
map<ID, Service_Order__c> testResults = new map<ID, Service_Order__c>([select ID, Name, (select ID, Name from Service_Order_Line__r) from Service_Order__c']);
Further down in the trigger, I'll need to reference the child objects, but I can't seem to find a syntax to make it work. How would I write the following to loop through the children of testResults?
for(Service_Order_Line childrenOfTestResults : testResults.Service_Order_Line__r) {
system.debug(childrenOfTestResults.Name);
}
I'm in the process of trying to consolidate the SOQL calls within a trigger of a particularly difficult sObject. This sObject has enough code running on it that we're pretty regularly hitting the 101 error--so it's time to clean up and bulkify where possible.
I've run the following to fill a map with an sobject, and the children of that sobject. Let's assume for the moment that Service_Order_Line is a child of Service_Order with a many-to-one relationship, and I've filtered this down so I'm only getting one Service_Order and maybe 5 or 10 Service_Order_Lines:
map<ID, Service_Order__c> testResults = new map<ID, Service_Order__c>([select ID, Name, (select ID, Name from Service_Order_Line__r) from Service_Order__c']);
Further down in the trigger, I'll need to reference the child objects, but I can't seem to find a syntax to make it work. How would I write the following to loop through the children of testResults?
for(Service_Order_Line childrenOfTestResults : testResults.Service_Order_Line__r) {
system.debug(childrenOfTestResults.Name);
}
-greg
All Answers
-greg