You need to sign in to do that
Don't have an account?
Lalitha Pavani Rallabandi 9
Dual list box
Hi,
My requirement is, upon selection of the contacts from the Dual List Box, it should display the selected contacts related accounts and opportunities. But it is not showing the related accounts and opportunities. Kindly help me. Here is my code:
Component:
Helper:
Please help me out on this.
My requirement is, upon selection of the contacts from the Dual List Box, it should display the selected contacts related accounts and opportunities. But it is not showing the related accounts and opportunities. Kindly help me. Here is my code:
Component:
<aura:component controller="ltngDualBox_Controller" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" > <!-- Attributes Start --> <aura:attribute name="listContacts" type="List" /> <aura:attribute name="selectedcontacts" type="List" /> <aura:attribute name="contacts" type="contact" /> <aura:attribute name="Accounts" type="Object" /> <aura:attribute name="Accountcolumns" type="List" /> <aura:attribute name="Opty" type="Object" /> <aura:attribute name="optycolumns" type="List" /> <!-- Attribute End --> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <div class="c-container" > <lightning:layout> <lightning:layoutItem padding="around-small" size="6"> <!-- List of contacts goes here --> <!-- Dual List Box Starts --> <lightning:dualListbox name="contacts" label="select a contact" fieldLevelHelp="Select your contact" options="{!v.listContacts}" onchange="{!c.handlechange}" /> </lightning:layoutItem> </lightning:layout> </div> <div style="height: 300px"> <lightning:layout> <lightning:layoutItem padding="around-small" size="6"> <lightning:card iconName="standard:account" title=" Accounts of selected contact" > <!-- Account List Goes Here --> <lightning:datatable data="{!v.Accounts}" columns="{!v.Accountcolumns}" keyField="Id" hideCheckboxColumn="true"/> </lightning:card> </lightning:layoutItem> </lightning:layout> <lightning:layout> <lightning:layoutItem padding="around-small" size="6"> <lightning:card iconName="standard:opportunity" title=" opportunities for selected contact" > <!-- opportunity List Goes Here --> <lightning:datatable data="{!v.Opty}" columns="{!v.optycolumns}" keyField="Id" hideCheckboxColumn="true"/> </lightning:card> </lightning:layoutItem> </lightning:layout> </div> </aura:component>Controller:
({ doInit : function(component, event, helper) { helper.getListofcontacts(component, event, helper); }, handlechange : function(component,event,helper){ helper.getSelectedContacts(component,event,helper); component.set("v.Accountcolumns", [ {label:"Name", fieldName:"Name", type:"text"}, {label:"Industry", fieldName:"Industry", type:"text"}, {label:"Phone", fieldName:"Phone", type:"phone"}, {label:"Rating", fieldName:"Rating", type:"text"} ]); helper.getSelectedopty(component,event,helper); component.set("v.optycolumns", [ {label:"Name", fieldName:"Name", type:"text"}, {label:"Amount", fieldName:"Amount", type:"decimal"}, {label:"LeadSource", fieldName:"LeadSource", type:"text"}, {label:"StageName", fieldName:"StageName", type:"text"} ]); } })
Helper:
({ getListofcontacts : function(component, event, helper) { //calling server side method to get contacts var action = component.get("c.getcontacts"); action.setParams({ }) action.setCallback(this,function(response){ var state=response.getState(); console.log('state:::',state); if(state === 'SUCCESS'){ var resultList=response.getReturnValue(); console.log('resultList:::',resultList); var contacts = []; resultList.forEach(function(result){ console.log('result:::',result); contacts.push({ label:result.Name, value:result.Id}); }); console.log('contacts::',contacts); component.set("v.listContacts",contacts); console.log('listContacts',component.get("v.listContacts")); } }); $A.enqueueAction(action); }, getSelectedContacts : function(component,event,helper){ var selectedcontact = event.getParam("value"); component.set("v.selectedcontacts",selectedcontact); console.log('selectedcontacts::',selectedcontact); var action=component.get("c.getaccounts"); action.setParams({ "Ids":component.get("v.selectedcontacts") }) action.setCallback(this,function(response){ var state= response.getState(); console.log('state:::'+state); if(state === 'SUCCESS'){ var accountresult = response.getReturnValue(); console.log('accountresult:::',accountresult); component.set("v.Accounts",accountresult); console.log('Accounts:::',component.get("v.Accounts")); } }); $A.enqueueAction(action); }, getSelectedopty : function(component,event,helper){ var selectedcontact = event.getParam("value"); component.set("v.selectedcontacts",selectedcontact); console.log('selectedcontacts::',selectedcontact); var action=component.get("c.getopty"); action.setParams({ "conId":component.get("v.selectedcontacts") }) action.setCallback(this,function(response){ var state= response.getState(); console.log('state:::'+state); if(state === 'SUCCESS'){ var optyresult = response.getReturnValue(); console.log('optyresult:::',optyresult); component.set("v.Opty",optyresult); console.log('oppo:::',component.get("v.Opty")); } }); $A.enqueueAction(action); } })
Please help me out on this.
Greetings!
It is very difficult for us to debug the code from our end as it is huge.However,You can debug the lightning components using the lightning inspector easily.The below document and video will guide you on the same.
https://www.youtube.com/watch?v=YgL0UNVoqQ8
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
I got the output. There is an error in my Apex class which is stoping to display the related Accounts and Opportunities. I am posting my code here so that it can help others in future....