0

Hi I have an object as Product and another object as Product Line items. What I am trying to do is fetch data from my Apex Controller in the form of Map which has Product as key and List of Line Items as values . Map<Product__c,List<Product_Line_Items__c>>

The problem is the way I am getting the map in Lightning component is (which I am seeing through console log )

enter image description here

The requirement is to iterate the map and get header object so that I can display the field values like below

enter image description here

So now in lightning component's controller this is the way I am fetching this map from apex controller

``

      action.setCallback(this, function(response){
             var state = response.getState();
            console.log(state);
            if (state === "SUCCESS") {
                var result =response.getReturnValue().mapProductToSKU;
               for(var key in result){
                    
                    arrayMapP.push({key: key, value: result[key]});
    } 
  component.set("v.ProducttoSKU",arrayMapP);

``

Now in component

<aura:attribute name="PNumbertoSKU" type="Map" /> <aura:iteration items="{!v.PNumbertoSKU}" var="PNumber1"> PNumber1.key.field name

Here I am seeing data in this way

[Product__c (Product....] I am not seeing that particular field value

0

I would recommend refactoring your Apex method to return the data in a different format.

For example, you could return a Map<String, Map<String, Object>> where the outer map is keyed on the product ID and the inner map contains keys like product (where the value is the Product__c object) and lineItems (whose value is a List<Product_Line_Items__c>).

Then your data will look more like this -- and you'll be better able to use it:

{
  blmK0000003Saaaaa: {
    product: {
      Id: "blmK0000003Saaaaa",
      Product_Description__c: "Product1",
      Quantity__c: 1,
      Total_Sales_Price__c: 2858.07
    },
    lineItems: [
      {
        Id: "blmK0000003xxxxx",
        Name: "SKU1",
        Quantity__c: 2,
        Total_Sales_Price__c: 6443.32,
      },
      {
        Id: "blmK0000003yyyyy",
        Name: "SKU1",
        Quantity__c: 2,
        Total_Sales_Price__c: 6443.32,
      }
    ]
  },
  blmK0000003Sbbbbb: {
    product: {
      Id: "blmK0000003Sbbbbb",
      Product_Description__c: "Product2",
      Quantity__c: 1,
      Total_Sales_Price__c: 2858.07
    },
    lineItems: [
      {
        Id: "blmK0000003zzzzz",
        Name: "SKU1",
        Quantity__c: 2,
        Total_Sales_Price__c: 6443.32,
      }
    ]
  },
  // etc...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.