+ Start a Discussion
KNKKNK 

Need help on wrapper class.

Hi Team,

 

Could you please help me with below warpper class.

 

public List<Measure__c> ActualList {get; set;} 

     public List<Measure__c> getActuals() {

        String accountId = ApexPages.currentPage().getParameters().get('id');

 List<string> ExistingProds  = new List<string>
 try{
 LIst<CustomForecast__c> MPExisting = [SELECT Product__c FROM CustomForecast__c Where Account__c = :accountId]
 for (CustomForecast__c mp : MPExisting {
                    Existingprods.add(mp.Product__c);
                }
   }


    
        List<Measure__c> ActualInvoice = [select Id, Name,Cross_Reference__c,Calendar__c,Value__c From Measure__c
        Where Cross_Reference__r.Customer_Company__c = :accountId AND Product__c = ExistingProds];
        return ActualInvoice;
       
    }

I want put the actual Inovoice Values with product into Map.

 

How can i do this. can any one help me here.

Like this I dont no whether this correct format or not   Map<String,List<Measure__c>> MeaMap = new Map Map<String,List<Measure__c>>();

Nish RajNish Raj

Hi KNK,

 

try this:

public List<Measure__c> ActualList {get; set;}

public Map<Product__c,List<Measure__c>> getActuals() {

    String accountId = ApexPages.currentPage().getParameters().get('id');
    Map<Product__c,List<Measure__c>> mapProductToInvoices = new Map<Product__c,List<Measure__c>>();

    List<string> ExistingProds  = new List<string>
    try{
        for(CustomForecast__c sObjCF : [SELECT Product__c FROM CustomForecast__c Where Account__c = :accountId]) {
        
            Existingprods.add(mp.Product__c);
        }
        
        if(!Existingprods.isEmpty()) {
        
            for(Measure__c sObjInvoice : [ select Id, Name,Cross_Reference__c,Calendar__c,Value__c, Product__c, Product__r.Id From Measure__c Where Cross_Reference__r.Customer_Company__c = :accountId AND Product__c = ExistingProds]) {
            
                List<Measure__c> lstTempMeasure;
                
                if(mapProductToInvoices.get(sObjInvoice.Product__c) == null) {
                
                    lstTempMeasure = new List<Measure__c>();
                }
                else {
                
                    lstTempMeasure = mapProductToInvoices.get(sObjInvoice.Product__c);
                }
                
                lstTempMeasure.add(sObjInvoice);
                mapProductToInvoices.put(sObjInvoice.Product__r,lstTempMeasure);
            }
        }
    }
    
    return mapProductToInvoices;
}