'I want to create an object from two different object, one is parrent object and another one is supposed to be a child

I want to create a new object from two different objects with a relational field in the child object is Section__c in relation to the Parent object Id. My parent object is as follows.

var section = [{ "Id": "a0L5w00000FAmpHEAT", "Name": "Risk", "orderNumber__c": 1 }, { "Id": "a0L5w00000FAmpIEAT", "Name": "Actions", "orderNumber__c": 2 }]

and child object is as follows with the relational field Section__c in relation to the parent object field Id

var agenda = [{ "Name": "Very High Risk", "AgendaName__c": "Very High Risk", "Section__c": "a0L5w00000FAmpHEAT", "Comments__c": "", "Completed__c": true, "Description__c": "70% and Above", "orderNumber__c": 1, "CreatedById": "0055w00000EDQ9sAAH" }, { "Name": "Low Risk", "AgendaName__c": "Low Risk", "Section__c": "a0L5w00000FAmpHEAT", "Comments__c": "", "Completed__c": true, "Description__c": "1% to 49%", "orderNumber__c": 3, "CreatedById": "0055w00000EDQ9sAAH" }, { "Name": "Item 01", "AgendaName__c": "Item 01", "Section__c": "a0L5w00000FAmpIEAT", "Comments__c": "", "Completed__c": true, "Description__c": "Des", "orderNumber__c": 1, "CreatedById": "0055w00000EDQ9sAAH" }, { "Name": "Item 02", "AgendaName__c": "Item 02", "Section__c": "a0L5w00000FAmpIEAT", "Comments__c": "", "Completed__c": true, "Description__c": "des", "orderNumber__c": 2, "CreatedById": "0055w00000EDQ9sAAH" }]

and I want a new object as follows agenda as a child to the relevant section

var NewRelationArr = [{
    "Id": "a0L5w00000FAmpHEAT",
    "Name": "Risk",
    "orderNumber__c": 1,
"agenda": [{
    "Name": "Very High Risk",
    "AgendaName__c": "Very High Risk",
    "Section__c": "a0L5w00000FAmpHEAT",
    "Comments__c": "",
    "Completed__c": true,
    "Description__c": "70% and Above",
    "orderNumber__c": 1,
    "CreatedById": "0055w00000EDQ9sAAH"
}, {
    "Name": "Medium Risk",
    "AgendaName__c": "Medium Risk",
    "Section__c": "a0L5w00000FAmpHEAT",
    "Comments__c": "",
    "Completed__c": false,
    "Description__c": "50% to 69%",
    "orderNumber__c": 2,
    "CreatedById": "0055w00000EDQ9sAAH"
}, {
    "Name": "Low Risk",
    "AgendaName__c": "Low Risk",
    "Section__c": "a0L5w00000FAmpHEAT",
    "Comments__c": "",
    "Completed__c": true,
    "Description__c": "1% to 49%",
    "orderNumber__c": 3,
    "CreatedById": "0055w00000EDQ9sAAH"
}]
}, {
    "Id": "a0L5w00000FAmpIEAT",
    "Name": "Actions",
    "orderNumber__c": 2,
    "agenda": [{
    "Name": "Item 01",
    "AgendaName__c": "Item 01",
    "Section__c": "a0L5w00000FAmpIEAT",
    "Comments__c": "",
    "Completed__c": true,
    "Description__c": "Des",
    "orderNumber__c": 1,
    "CreatedById": "0055w00000EDQ9sAAH"
}, {
    "Name": "Item 02",
    "AgendaName__c": "Item 02",
    "Section__c": "a0L5w00000FAmpIEAT",
    "Comments__c": "",
    "Completed__c": true,
    "Description__c": "des",
    "orderNumber__c": 2,
    "CreatedById": "0055w00000EDQ9sAAH"
}, {
    "Name": "Item 03",
    "AgendaName__c": "Item 03",
    "Section__c": "a0L5w00000FAmpIEAT",
    "Comments__c": "",
    "Completed__c": true,
    "Description__c": "",
    "orderNumber__c": 3,
    "CreatedById": "0055w00000EDQ9sAAH"
}]

}]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source