function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raksha NarayanRaksha Narayan 

LWC: Iterating list<SObject> from the map<String,list<SObject>> on the html to print the list<SObject> values in table format

I have created a LWC in order to print the sobject data in a table. for that I have created a map<String,list<SObject>>. From the debug logs, i found that the map holds the data in the below format: 
mymap{Case=(Case:{Id=5002f0000043zxWAAQ, ContactId=0030c00002kebMSAAY, CaseNumber=00678068}), Event=(Event:{Id=00U2f0000018Ly0EAE, WhoId=0030c00002kebMSAAY, Subject=Test event, Type=Email})}.
Now i need to iterate over the List<Sobject> value to print the values in a table as below.
for case:
idcontactidcase number
for event:
00U2f0000018Ly0EAETest eventEmail
The row and column should be printed in the table dynamically by picking the data from the list<sobject> (no hardcoding of the values in datatable or in html).
Please let me know how this can be achieved
We can not directly iterate sObject list in LWC as it doesn't support (.) dot notation. So we need to use JavaScript here. This is how sample code will look like
renderedCallback() {
        if(!this.fieldName.includes('.')) {
   = this.sobject[this.fieldName];
        else {
   = this.sobject[this.fieldName.split(".")[0]][this.fieldName.split(".")[1]]; //Here we are fetching data from parent field

You can check below post to get complete details.
Raksha NarayanRaksha Narayan
Hi Tushar,
In the above link, the html is hardcoded with the field name. i.e.,
<c-lwcs-object key={sobKey.key} sobject={sobKey.value} field-name="Name"></c-lwcs-object>
I do not want to hardcode the field name. instead it should fetch the fields directly from the list<sobject>. Please suggest
You don't need to hardcode this. Just bind a variable. If you have noticed I am just passing field name as string variable.