0

I have a aggregate list which is returned only summary of 6 values. I want them to be displayed as percentage vales in a tables with 2 columns. First column is for the description of the summary value (Sting in the Map) and the second column is for the summary value (Value in the Map). This is my code. but I don't know how to return them into lightning component as a table. There are only 4 values to be iterated.

public class Wk_TraineePerformanceAuraController {
    @AuraEnabled
    public static List<Wk_PerformanceQueryResults> getTraineeProgress(){
        //Get looged in user details
        User loggedInUser = [SELECT Id,
                             ContactId,
                             Contact.AccountId,
                             Contact.Company_Contact__c
                             FROM User
                             WHERE ID=: UserInfo.getUserId() LIMIT 1];
        System.debug('=loggedInUser===='+loggedInUser);

        List<AggregateResult> agrResults=
            [Select 
             Sum(Achieved_Credits_to_Rpting_Yr_End__c) achivedCredit,
             Sum(PC_Credits_Total__c) pcCredit,
             Sum(Programme_Credits__c) progCredits,
             Count(X10_Credit_Minimum_No__c) tenCreditMin,
             Count(X1_Credit_Minimum_No__c) oneCreditMin,
             Count(Enrolled_in_Rpt_Year_No__c) enrRptYr
             FROM  Funding_Cycles_TA__c 
             WHERE Enrolled_in_Rpting_Yr__c=True  
             AND (Training_Agreement__r.Funding_Source__c ='IT - Industry Training' 
                  OR Training_Agreement__r.Funding_Source__c ='UF - Un-funded')
             AND Reporting_Year__c =THIS_YEAR
             AND Training_Agreement__r.Company_Id__c ='00130000010vWo6'];
 Map<String,decimal> agMap = new Map<String,decimal>();

        for(AggregateResult ar: agrResults){
            agMap.Put(('Progress'),(Decimal)ar.get('achivedCredit')*100/(Decimal)ar.get('progCredits'));
            agMap.Put(('Completions'),(Decimal)ar.get('pcCredit')*100/(Decimal)ar.get('progCredits'));
            agMap.Put(('Active'),(Decimal)ar.get('oneCreditMin')*100/(Decimal)ar.get('enrRptYr'));
            agMap.Put(('Progressive'),(Decimal)ar.get('tenCreditMin')*100/(Decimal)ar.get('enrRptYr'));
        }
}
}

I know how to code the component if I return the data as a table.

Thanks

4
  • where is your lightning component - controller? are you asking for someone to provide you the code? Have you done the trailheads on lightning components?
    – glls
    Jun 29, 2017 at 3:40
  • A Map really isn't want you want. You'd want a list of objects or something like that.
    – sfdcfox
    Jun 29, 2017 at 3:42
  • I have written similar code for components and controllers. I just need to return method for tow columns. As the first column (Description) is just created. only 4 values returning from aggregate results. and wants combine and return as a table. that why I thought use as a map
    – Jay Weera
    Jun 29, 2017 at 4:57
  • no room to send the code for component and controller
    – Jay Weera
    Jun 29, 2017 at 5:15

1 Answer 1

0

Use following code for your requirement

<aura:component controller="Wk_TraineePerformanceAuraController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="myMap" type="Map" />
{!v.myMap.key1} 
{!v.myMap.key2}<br/>

({ doInit: function(component, event, helper) {

   var action = component.get('c.getTraineeProgress');

    action.setCallback(this,function(response){           
        component.set('v.myMap',response.getReturnValue());
    });
    $A.enqueueAction(action);
 }

})

public class Wk_TraineePerformanceAuraController { @AuraEnabled public static Map getTraineeProgress(){ //Get looged in user details User loggedInUser = [SELECT Id, ContactId, Contact.AccountId, Contact.Company_Contact__c FROM User WHERE ID=: UserInfo.getUserId() LIMIT 1]; System.debug('=loggedInUser===='+loggedInUser);

    List<AggregateResult> agrResults=
        [Select 
         Sum(Achieved_Credits_to_Rpting_Yr_End__c) achivedCredit,
         Sum(PC_Credits_Total__c) pcCredit,
         Sum(Programme_Credits__c) progCredits,
         Count(X10_Credit_Minimum_No__c) tenCreditMin,
         Count(X1_Credit_Minimum_No__c) oneCreditMin,
         Count(Enrolled_in_Rpt_Year_No__c) enrRptYr
         FROM  Funding_Cycles_TA__c 
         WHERE Enrolled_in_Rpting_Yr__c=True  
         AND (Training_Agreement__r.Funding_Source__c ='IT - Industry Training' 
              OR Training_Agreement__r.Funding_Source__c ='UF - Un-funded')
         AND Reporting_Year__c =THIS_YEAR
         AND Training_Agreement__r.Company_Id__c ='00130000010vWo6'];
    Map<String,decimal> agMap = new Map<String,decimal>();

    for(AggregateResult ar: agrResults){
        agMap.Put(('Progress'),(Decimal)ar.get('achivedCredit')*100/(Decimal)ar.get('progCredits'));
        agMap.Put(('Completions'),(Decimal)ar.get('pcCredit')*100/(Decimal)ar.get('progCredits'));
        agMap.Put(('Active'),(Decimal)ar.get('oneCreditMin')*100/(Decimal)ar.get('enrRptYr'));
        agMap.Put(('Progressive'),(Decimal)ar.get('tenCreditMin')*100/(Decimal)ar.get('enrRptYr'));
    }
    return agmap;
}

}

Thank you, Amol Salve Salesforce Developer

1
  • Thanks Amol, I tried this But I get a blank page. Should I change the myMap.key1 and myMap.key2. The key1 and key2 is not defined. Is that the issue? thanks
    – Jay Weera
    Jun 29, 2017 at 7:35

You must log in to answer this question.

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