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
Javier CGJavier CG 

Show class field values on Lightning Component with iteration

I have to show a table with the contents of opportunitylineitems from an opportunity. Moreover, the user can select different items to make a mass action with them.
But when I try to show the items data, the LC don´t show anything.

Component:
<aura:component controller="GPController" implements="force:hasRecordId,flexipage:availableForRecordHome">
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="Products" type="GPController.wrapperGP[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />   
    <table>
        <thead>
            <tr>
                <th>
                    Selected
                </th>
                <th>
                    Product
                </th>
                <th>
                    Last modified date
                </th>
                <th>
                    Created by
                </th>
            </tr>
        </thead>
        <tbody>    
            <aura:iteration items="{!v.Products}" var="prod">
                <tr>
                    <td>
                        {!prod.Selected}
                    </td>
                    <td>
                        {!prod.Name}
                    </td>
                    <td>
                        {!prod.LastModifiedDate}
                    </td>
                    <td>
                        {!prod.CreatedBy.Name}
                    </td>
                </tr>                
            </aura:iteration>
        </tbody>
    </table>    
</aura:component>

Controller:
({
    doInit : function(component, event)
    {        
        var action = component.get("c.getProducts");
        action.setParams({
            "IdOpp": component.get("v.recordId")
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS")
            {
                component.set("v.Productos", response.getReturnValue());
               }
            else
            {
                console.log("Failed with state: " + state);
            }
        });
        $A.enqueueAction(action);
    },
})

Apex controller:
public class GPController
{
    @AuraEnabled
    public static List<wrapperGP> getProducts(ID IdOpp)
    {
        wrapperGP[] ListGP = new wrapperGP[]{};
        GP__c[] GPList = [select Id, Name, LastModifiedDate, CreatedBy.Name
                                                    from GP__c where Opp__c = :IdOpp];
        for (GP__c GP: GPList )
        {
            wrapperGP newGP= new wrapperGP(GP);
            ListGP.Add(newGP);
        }
        return ListGP ;
    } 
    public class wrapperGP
    {
        public boolean Selected {get; set;}
        public GP__c GP {get; set;}
        
        public wrapperGP(GP__c  newGP)
        {
            GP = newGP;
            Selected = false;
        }
    }
}

If I write fixed text on each iteration, 2 rows are painted because the opportunity has 2 items and if I show the iteration prod var on each iteration using {!prod}, shows [object Object], but the field content (example: {!prod.Name}) don´t show anything.
I have created the wrapper to insert the checkbox in the record and control later if the item is checked or not, to realize the mass action on it. I don´t know if there is an easier way to do that.
Best Answer chosen by Javier CG
Javier CGJavier CG
Finally I have solved the issue.
The problem was:
  1. I have to @AuraEnabled the variables inside wrapperGP class
  2. Access to the values with !prod.GP.Name