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
john miirjohn miir 

how to get the account related quotes into an lightning component

HI,
I want to create a lightning component where i need to pass the current account Id to the component and display all the quotes that are related to the account id.
 
Best Answer chosen by john miir
GauravGargGauravGarg
Component:
<aura:component>
    <aura:attribute name="recordId" type="string" />
    <aura:attribute name="data" type="[]" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:if isTrue="{!data}">
    </aura:if>
</aura:component>
JS Controller:
    doInit: function(component, event, helper) {
        var action = component.get("c.getQuotes");

        action.setParams({
            accountId: component.get("v.recordId")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            var t = JSON.parse(response.getReturnValue());
            component.set("v.data", t);
        });
        $A.enqueueAction(action);
    },
 
APex Class:

    public with sharing class {
        @auraEnabled
        public static List < Quotes > quotes(String accountId) {
            if (accountID != NULL)
                List < Quotes > q = [SELECT Id, Name FROM QUOTES WHERE Account =: AccountId]
            return (q);
        }
    }


Hope this gives an overall idea of how to Call Apex class from Component and retrieve value to display back on the UI leve. 

Thanks,

Gaurav
Skype: gaurav62990