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
larvalarva 

Create lightning aura component

Create lightning aura component with an apex controller to retrieve and display all order items related to the order as well as the discount and total order amounts?
Best Answer chosen by larva
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please find the solution.

<aura:component controller="OrderAuraController">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     
 	<aura:attribute name="OrderItemList" type="List"  />
    
             
              <table class="slds-table slds-table_bordered slds-table_cell-buffer">
            <thead>
                <tr class="slds-text-title_caps">
                    <th scope="col">
                        <strong><div class="slds-truncate" title="TotalPrice">TotalPrice</div></strong>
                    </th>
                    <th scope="col">
                        <strong><div class="slds-truncate" title="Quantity">Quantity</div></strong>
                    </th>
                   
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.OrderItemList}" var="con"> 
                    <tr>
                        <th scope="row" data-label="TotalPrice">
                            <div class="slds-truncate" title="{!con.TotalPrice}">{!con.TotalPrice}</div>
                        </th>
                        <th scope="row" data-label="Quantity">
                            <div class="slds-truncate" title="{!con.Quantity}">{!con.Quantity}</div>
                        </th>
                      
                    </tr>
                </aura:iteration> 
            </tbody>
        </table>
        
             
            
</aura:component>
 
({
    doInit: function(component, event, helper) {
        
        helper.getContactList(component, event, helper);
    }
     
    
})
 
({
    getContactList: function(component, event, helper) {
        var action = component.get("c.getOrderData");
         
        action.setCallback(this, function(result) {
            var state = result.getState();
            if (component.isValid() && state === "SUCCESS"){
                var resultData = result.getReturnValue();
                component.set("v.OrderItemList", resultData);
                 
            }
        });
        $A.enqueueAction(action);
    }
})
 
public class OrderAuraController {
    @AuraEnabled
    public static List<OrderItem> getOrderData() {
         List<Order> orderList=new List<Order>([Select Id from Order limit 100]);
		 
		 List<OrderItem> orderItemList=new List<OrderItem>([Select Id,TotalPrice,Quantity from OrderItem where orderid in : orderList]);
        
        return orderItemList;
    }
     
     
}


Please mark it as The Best Answer if it helps you

Thank You