You need to sign in to do that
Don't have an account?

Lightning component - Display Unique Opportunity field values for account
I am trying to build a basic component which displays the unique values of a field from all opportunities under an open account.
I'm getting the following error: Illegal conversion from List to List
Any help is greatly appreciated. Here's the code:
Class:
public class testclass { @AuraEnabled public static List<Opportunity> fetchOpp(String key) { List<AggregateResult> listOfOpps = [SELECT Consulting_Engineer__c, COUNT(ID) FROM Opportunity WHERE AccountId =:key GROUP BY Consulting_Engineer__c]; return listOfOpps; } }
Component:
<aura:component controller= "testclass" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" > <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="Opportunities" type="Opportunity[]"/> <ul> <aura:iteration items="{!v.Opportunities}" var="opportunity"> <li>{!opportunity.Consulting_Engineer__c}</li> </aura:iteration> </ul> </aura:component>
Controller:
({ doInit: function(component, event, helper) { var action = component.get('c.fetchOpp'); var rid = component.get("v.recordId"); action.setParams({key : rid}); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { component.set('v.Opportunities', response.getReturnValue()); } }); $A.enqueueAction(action); } })
Please find the updated code below:
Component: Controller:
Apex Class: Please let me know if there is any issue with this.
Thanks,
Abhishek Bansal.
All Answers
Please find the updated code below:
Component: Controller:
Apex Class: Please let me know if there is any issue with this.
Thanks,
Abhishek Bansal.
Thanks again Abhishek.
I only had to change to following line: <aura:attribute name="listOfConsultingEnigeer" type="List<String>"/>. It wouldn't accept List<String> so I changed it to just String.
Everything is working except there is a single value that isn't showing. Might it be because there is a '/' in the string?
Hi Tyler,
Having a slash in the string is not an issue. Please change the attribute type from string to just List.
Change List<String> -> List
I hope that will resolve the issue.
Thanks,
Abhishek Bansal