I have array of object which contains two different objects data e.g Secction__c and Question__c
@track addSectionRecord = [
{
id: '',
section: '',
sort: '',
Question: [{
subQues: '',
sort: ''
}]
}
];
Now i want to pass this array of object to apex method like that
apexMethod({apexList:this.addSectionRecord})
from JavaScript. Firstly how to declared the list apexList
in apex.Secondly how to iterate the list in apex to get data for these two obejects.
Best Answer
apexList
could be defined as follows:Actually processing this uses a nested loop:
However, please note that
sort
is an Apex reserved keyword. The above code renames sort to sortOrder to avoid compile errors. If you do not want to refactor the client code, you can instead use a Map/List:However, this code has a caveat that some people have had trouble with automatic serialization, so you might end up having to convert this to a JSON string (at which point, you'll need to modify client code anyways, so you should probably fix it to use the first version I've mentioned here anyways).
...