I am fairly new to apex and lightning components so I struggle with a probably simple request. I want to pass an account field (berufskategorie__c) to the lightning component paramater (main) which then should get passed to the apex class variable (:main).
Here is my apex class:
public with sharing class ReferenzkundeNachKategorie {
@AuraEnabled
public static List<AggregateResult> getList (String main) {
list<AggregateResult> CampaignList = [
SELECT company__c, Count(Id)
FROM Anzeigen_bersicht__c
WHERE Start_in_Tagen__c <= 365 AND id in (select Anzeigen__c FROM Kategorie__c WHERE Main__c = :main)
GROUP BY company__c
ORDER BY Count(Id) DESC
LIMIT 10
];
return CampaignList;
}}
Here my component:
<aura:component controller = "ReferenzkundeNachKategorie" implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:availableForFlowScreens" access="global" >
<aura:attribute name="AnzeigenList" type="list" />
<aura:attribute type="AggregateResult[]" name="CampaignList" />
<aura:attribute name="mycolumns" type="list" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:datatable data="{! v.CampaignList }"
columns="{! v.AnzeigenList }"
keyField="id"
hideCheckboxColumn="true"/>
</aura:component>
Here my controller
({
init: function(component, event, helper) {
component.set('v.AnzeigenList', [
{label: 'Unternehmen', fieldName: 'company__c', type: 'text'},
{label: 'Anzahl Anzeigen', fieldName: 'expr0', type: 'integer'}
]);
var campList = component.get("c.getList");
campList.setParams
({
main: component.get("v.main__c")
});
campList.setCallback(this, function(data)
{
component.set("v.CampaignList", data.getReturnValue());
});
$A.enqueueAction(campList);
}
})
When I hardcode my apex class to
WHERE Start_in_Tagen__c <= 365 AND id in (select Anzeigen__c FROM Kategorie__c WHERE Main__c = 'somehardcodedvalue')
the result looks like this
The part that baffles me is where do I say that the value for 'main' should be from the account field "berufskategorie__c" as I need dynamic results based on the account values.
Thanks in advance!