I have a Parent Object let's call it X__c
and I have 4 child objects Ax__c, Bc__c, Cc__c, Dc__c
I'm trying to create a List of Wrapper class out of the following data structure:
The above data structure would be saved in the following collections:
Map<X__c, List<Ax__c>>
Map<X__c, List<Bc__c>>
Map<X__c, List<Cc__c>>
Map<X__c, List<Dc__c>>
Wrapper Class:
public wrapclass {
X__c parent;
Ax__c childA;
Bc__c childB;
Cc__c childC;
Dc__c childD;
}
I want to save all the combinations of all the child records related to the same parent record in a List<wrapclass>
So at the end of it I want my List<wrapclass>
to look like this:
wrapclasslist = [
{
parent = X__c,
childA = Ax__c -1,
childB = Bx__c - 2
},
{
parent = X__c,
childA = Ax__c -2,
childB = Bx__c - 2
},
{
parent = X__c,
childA = Ax__c -2,
childB = Bx__c - 1
},
{
parent = X__c,
childA = Ax__c -1,
childB = Bx__c - 1
}
];
I know this can be done using nested for loops but, I'm looking for a more optimized solution. Any help is appreciated