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
Vidya H 4Vidya H 4 

i am displaying account records and am not able to display total number of contact and opportunity records created under account

Controller

public class AccountAuraClr
 {
                @AuraEnabled
    public static List<Account> getAccountRecord()
   {
        return new List<Account>([Select id,Name,Phone,Type from Account where Type != null LIMIT  100]);
    }
}

Component

<aura:component controller="AccountAuraClr" implements="force:appHostable,forceCommunity:availableForAllPageTypes,
flexipage:availableForAllPageTypes" access="global">
 <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <!-- calling doInit method in Component Controller -->
    <aura:attribute name="accLst" type="Account[]"/> <!-- create Array type Account variable-->
    <article class="slds-card">
      <div class="slds-card__header slds-grid">
        <header class="slds-media slds-media_center slds-has-flexi-truncate">
          <div class="slds-media__figure">
            <span class="slds-icon_container slds-icon-standard-account" title="description of icon when needed">
                <lightning:icon iconName="standard:account" size="large" alternativeText="List account"/>
            </span>
          </div>
          <div class="slds-media__body">
            <h2 title="Survey">
           <!--   <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Account">
                <span class="slds-text-heading_small">Survey</span>
              </a>-->
            </h2>
          </div>
        </header>
       </div>
      <div class="slds-card__body">
        <table class="slds-table slds-table_bordered slds-no-row-hover slds-table_cell-buffer">
          <thead>
            <tr class="slds-text-title_caps">
              <th scope="col">
                <div class="slds-truncate" title="Name">Account Name</div>
              </th>
              <th scope="col">
                <div class="slds-truncate" title="Type">Total number of Contacts</div>
              </th>
                <th scope="col">
                <div class="slds-truncate" title="Type">Total number of Opportunity</div>
              </th>
              <th scope="col">
                <div class="slds-truncate" title="Phone">Delete</div>
              </th>
            </tr>
          </thead>
          <tbody>
              <aura:iteration items="{!v.accLst}" var="acc"> <!-- iteration account record.-->
                  <tr class="slds-hint-parent">
                      <th scope="row">
                          <div class="slds-truncate" title="Adam Choi"><a href="javascript:void(0);">{!acc.Name}</a></div>
                      </th>
                      <td>
                          <div class="slds-truncate" title="Company One">{!acc.Type}</div>
                      </td>
                      <td>
                          <div class="slds-truncate" title="Company One">{!acc.Type}</div>
                      </td>
                      <td>
                          <a onclick="{!c.RemoveRecord}" data-record="{!index}">
                                        <lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
                                        <span class="slds-assistive-text">Delete</span>
                                    </a>
                      </td>
                      
                  </tr>                     
              </aura:iteration>
          </tbody>
        </table>
      </div>
      <footer class="slds-card__footer"><a href="javascript:void(0);"><!--View All <span class="slds-assistive-text">entity type</span>--></a></footer>
    </article>
</aura:component>

js controller:-

({
                doInit : function(component, event, helper) {
                                helper.getAccontRecord(component); // Calling Helper method
                },
      RemoveRecord : function(component, event, helper) {
                                helper.removeRecord(component); // Calling Helper method
                }
})

js helper:-

({
                getAccontRecord : function( component ) {
                                var action = component.get("c.getAccountRecord"); //Calling Apex class controller 'getAccountRecord' method

        action.setCallback(this, function(response) {
            var state = response.getState(); //Checking response status
            var result = JSON.stringify(response.getReturnValue());
            if (component.isValid() && state === "SUCCESS")
                component.set("v.accLst", response.getReturnValue());  // Adding values in Aura attribute variable.   
        });
        $A.enqueueAction(action);
                },
    removeRecord: function(component, event, helper) {
        //Get the account list
        var accountList = component.get("v.getAccountRecord");
        //Get the target object
        var selectedItem = event.currentTarget;
        //Get the selected item index
        var index = selectedItem.dataset.record;
        //Remove single record from account list
        accLst.splice(index, 1);
        //Set modified account list
        component.set("v.accLst", accLst);
    }
})