I'm working on a lightning:select tag to display account names in the dropdown list, whenever I select an account from the list it shows all the opportunities but I want only account related opportunities for that I'm passing ID parameter to the apex controller but it's not showing anything.


<aura:component controller="BookFaircls"> 
    <aura:attribute name="account" type="Account[]" />
    <aura:attribute name="opportunity" type="Opportunity[]" />
    <aura:attribute name="Id" type="ID"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <lightning:select name="selectItem" aura:id="selectItem" label="" onchange="{!c.oppRecords}">
    <aura:iteration items="{!v.account}" var="acc">
    <option value="{!acc.Id}">{!acc.Name}</option>
    <aura:iteration items="{!v.opportunity}" var="opp"> {!opp.Name} </aura:iteration>


        doInit : function(component, event, helper) { 
        var action = component.get("c.getAccountNames");
         action.setCallback(this, function(response){
         component.set("v.account", response.getReturnValue());

        oppRecords : function(component, helper){ 
        var value = component.get("c.getOpportunityDetails");
        value.setParams({Id :component.get("v.Id")}); value.setCallback(this,function(res){ 

        component.set("v.opportunity", res.getReturnValue()); })
  • 1
    what you have tried , Shared the code.
    Nov 22, 2017 at 10:30
  • 1
    @anu Next time updated the code in question itself .
    Nov 22, 2017 at 12:26
  • 1
    Hi @anu, you can click the edit link the to bottom left of your post and add the code to your question directly, no need to post a new question.
    – Folkert
    Nov 22, 2017 at 12:36
  • As I see your doInit function there is no action.setParams method to set parameter. Nov 22, 2017 at 13:03
  • I want setParams method in oppRecords method not in doInit and I need to pass setParams value to the Apex method.
    – anu
    Nov 22, 2017 at 13:09

1 Answer 1


As you missed the attribute value="", you can't get the selected value. So you should mention the attribute value="{!v.Id}"in lightning:select component.

<lightning:select name="selectItem" aura:id="selectItem" label="" value="{!v.Id}" onchange="{!c.oppRecords}">
    <aura:iteration items="{!v.account}" var="acc">
    <option value="{!acc.Id}">{!acc.Name}</option>
  • Thanks for your response, I tried your code but still no opportunities getting.
    – anu
    Nov 27, 2017 at 8:57
  • @anu did you check in the controller component.get("v.Id") whether you getting the selected AccountId. Can you check your code again because I think it's working fine.
    – Dhinesh
    Nov 27, 2017 at 9:41
  • In component controller I'm setting the "Id" value here: var action = component.get("c.getOpportunityDetails"); action.setParams({ Id : component.get("v.Id") });
    – anu
    Nov 27, 2017 at 13:36
  • @anu - make sure you get the value in console.log(component.get("v.Id")); , if yes, check your apex controller.
    – Dhinesh
    Nov 27, 2017 at 13:58
  • Thanks, I'm getting AccountId in the console but that accountId is not passing a parameter to apex controller method: here is my code is there any mistake I did? please help me @AuraEnabled public static List<Opportunity> getOpportunityDetails(String id){ List<Opportunity> opps = [select name from Opportunity where AccountId =:id]; return opps; }
    – anu
    Nov 27, 2017 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .