0

I am trying to use the wrapper class variables values in my jscontroller and please help me

I have a

public Map<String,FinancialSummary> reservesSummaryHeader{}

In which I am using wrapper class as values so how can i access that wrapper class values using that MAP key

This is my APex class-

public with sharing class ClaimsController1 {

     @AuraEnabled   
    public static Map<String,FinancialSummary> getallRecord(){
        ClaimsController1 obj = new ClaimsController1();


         return obj.reservesSummary;
    }

    @AuraEnabled
    public Map<String,List<String>> transactionTypesMap{
        get{
            if(transactionTypesMap == NULL){
                transactionTypesMap = new Map<String,List<String>>();
                for(Selectoption sp : Utils.getPicklistValues('Reserve_Level_2__c', 'Financials__c')){                  
                    String mainLevel = sp.getValue().substringBefore('-');                  
                    if(!transactionTypesMap.containsKey(mainLevel)){
                        transactionTypesMap.put(mainLevel,new List<String>());                      
                    }
                    transactionTypesMap.get(mainLevel).add(sp.getValue());                  
                }
            }
            return transactionTypesMap;
        }
        set;
    }

    @AuraEnabled    
    public Map<String,Decimal> paymentsSummaryHeader {
        get{
            if(paymentsSummaryHeader == null){          
            paymentsSummaryHeader = new Map<String,Decimal>();
            for(String opt : transactionTypesMap.keySet()){
                    if(!paymentsSummaryHeader.containsKey(opt)){
                        paymentsSummaryHeader.put(opt,0.00);
                    }
                }
                for(AggregateResult agr :[SELECT Reserve_Main__c,SUM(Amount__c) total_Amount FROM Financials__c 
                                                WHERE Claim__c=:'a009000003aE68L' AND RecordType.DeveloperName='Payment' GROUP BY Reserve_Main__c]){
                    paymentsSummaryHeader.put((String)agr.get('Reserve_Main__c'),(Decimal)agr.get('total_Amount'));         
                }           
            }
            return paymentsSummaryHeader;
        }
        set;
    }

     @AuraEnabled
     public Map<String,Decimal> paymentsSummary {
        get{
            if(paymentsSummary == null){            
                paymentsSummary = new Map<String,Decimal>();
                for(String mainOpt : transactionTypesMap.keySet()){
                    for(String lowerOpt : transactionTypesMap.get(mainOpt)){
                        if(!paymentsSummary.containsKey(lowerOpt)){
                            paymentsSummary.put(lowerOpt,0.00);
                        }                       
                    }
                }           
                for(AggregateResult agr :[SELECT Reserve_Level_2__c,SUM(Amount__c) total_Amount FROM Financials__c 
                                                WHERE Claim__c=:'a009000003aE68L' AND RecordType.DeveloperName='Payment' GROUP BY Reserve_Level_2__c]){
                    paymentsSummary.put((String)agr.get('Reserve_Level_2__c'),(Decimal)agr.get('total_Amount'));            
                }           
            }
        return paymentsSummary;
        }
        set;
    }   

    @AuraEnabled
    public Map<String,FinancialSummary> reservesSummaryHeader {
        get{            
            if(reservesSummaryHeader == NULL){
                reservesSummaryHeader = new Map<String,FinancialSummary>();
                for(String opt : transactionTypesMap.keySet()){
                    if(!reservesSummaryHeader.containsKey(opt)){
                        reservesSummaryHeader.put(opt,new FinancialSummary());
                    }
                }
                for(AggregateResult agr :[SELECT Reserve_Main__c,SUM(Amount__c) total_Amount FROM Financials__c 
                                                WHERE Claim__c=:'a009000003aE68L' AND RecordType.DeveloperName='Estimate' AND is_Reserve_Reduction__c=false GROUP BY Reserve_Main__c]){
                    String type = (String)agr.get('Reserve_Main__c');
                    reservesSummaryHeader.put(type,new FinancialSummary(agr.get('total_Amount'),paymentsSummaryHeader.get(type)));
                }
            }
            return reservesSummaryHeader;               
        }
        set;
    }   

    @AuraEnabled
    public Map<String,FinancialSummary> reservesSummary {
        get{
            if(reservesSummary == NULL){
                reservesSummary = new Map<String,FinancialSummary>();
                for(String mainOpt : transactionTypesMap.keySet()){
                    for(String lowerOpt : transactionTypesMap.get(mainOpt)){
                        if(!reservesSummary.containsKey(lowerOpt)){
                            reservesSummary.put(lowerOpt,new FinancialSummary());
                        }                       
                    }

                }
                 //system.debug('Hello123'+reservesSummary);
                for(AggregateResult agr :[SELECT Reserve_Level_2__c,SUM(Amount__c) total_Amount FROM Financials__c 
                                                WHERE Claim__c=:'a009000003aE68L' AND RecordType.DeveloperName='Estimate' AND is_Reserve_Reduction__c=false GROUP BY Reserve_Level_2__c]){
                    String type = (String)agr.get('Reserve_Level_2__c');

                    reservesSummary.put(type,new FinancialSummary(agr.get('total_Amount'),paymentsSummary.get(type)));

                }
                // 
            }
            system.debug('hellLokesh'+reservesSummary.keySet());
            return reservesSummary;             
        }
        set;
    }



     //Sub Class for Summary display
    public class FinancialSummary{
        //public String reserveCode; 
        public Decimal balanceAmount {get; set;}
        public Decimal totalAmount {get; set;}      
        public Decimal newValue {get; set;}
        public Decimal totalPaidAmount {get; set;}

        public FinancialSummary(Object amount,Object paidAmount){//String reserveCode,
            //this.reserveCode = reserveCode;
            this.totalAmount = (Decimal)amount;
            this.totalPaidAmount = (Decimal) paidAmount;
            this.newValue = 0.00;
            this.balanceAmount = this.totalAmount != null ? (this.totalAmount - (Decimal) paidAmount) : 0.00;


        }
        public FinancialSummary(){
            this.balanceAmount = 0.00;
            this.totalAmount = 0.00;
            this.newValue = 0.00;
            this.totalPaidAmount = 0.00;
            //this.reserveCode = NULL;
        }
    }


}

and this is my js Controller

({
      doInit : function(component, event, helper) {
     //call apex class method
    var action = component.get('c.getallRecord');
    action.setCallback(this,function(response){
        //store state of response
        var state = response.getState();
        if (state === "SUCCESS") {
           //Create an empty array to store the map keys 
                var arrayMapKeys = [];
                //Store the response of apex controller (return map)     
                var result = response.getReturnValue();
                //Set the store response[map] to component attribute, which name is map and type is map.   
                component.set('v.mapValues', result);

                for (var key in result) {
                    arrayMapKeys.push(key);
                    console.log('hello12'+result[key]);
                    var dbh = result[key];
                    console.log('hello12'+JSON.stringify(dbh));
                }
                //Set the list of keys.     
                component.set('v.mapKeyList', arrayMapKeys);
            //component.set('v.objClassController',JSON.stringify(response.getReturnValue()));
        }
   });
    $A.enqueueAction(action);
    },
})
  • What issue are you having? You seem to have written code to do this. – David Reed Jan 3 '19 at 12:41
  • 1
    How many accounts do you have? Please refrain from having multiple accounts – Pranay Jaiswal Jan 3 '19 at 12:44
3

The attributes need to be @AuraEnabled. A getter/setter will not help you here.

    @AuraEnabled public Decimal balanceAmount;
    @AuraEnabled public Decimal totalAmount;
    @AuraEnabled public Decimal newValue;
    @AuraEnabled public Decimal totalPaidAmount;

You can read more about it in Returning Data from an Apex Server-Side Controller.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.