I have sObject1 called sObject1__c
which is a parent(master-detail) to many sObjects2 each called sObject2__c
.
So in my trigger I have an empty list of sObject2 related to sObject1:
sObject1__c.sObject2s__r = ();
So then I query for sObject2 and iterate over the returned list of results assigning its values to sObject1 like this:
sObject1__c.sObject2s__r.add(sObject2__c);
The code builds however the list sObject1__c.sObject2s__r
remains empty. System.debug(sObject2__c)
shows me that the object holds a value. Nonetheless that object doesn't get assigned to the corresponding list in sObject1.
EDIT
Here's some code as requested:
List<Interview_Result__c> listOfTestResults = [
SELECT
Test_Field__c
FROM Test_Result__c
WHERE Test_Process__c IN : mapOfTP.keySet()
];
for (Test_Process__c tprocess : mapOfTP.values()) {
for (Test_Result__c tresult : listOfTestResults) {
if (tprocess.Id == tresult.Test_Process__c) {
tprocess.Test_Results__r.add(tresult);
}
}
}
Please note that the tprocess.Test_Results__r
is empty before I start adding to it.