Can anyone help me with this? How to write a Logic for the current and future data to get displayed in a separate row in visual force page PDF. I have written a condition where it gives the current data, and future data but gets added in the same quater , but it should get split in a row. So looking for the logic for the future year. Any help very much appreciated.

ProductName         Year       Q1       Q2   Q3    Q4       Total
BXRC-25e4000-F-04  2014       5200     200   300   400       6100 
BXRC-25e4000-F-23  2014       200                 200        400
Subtotal ------------         5400     200   300   600       6500

For Example: In the above table I get the data for the Year 2014 with their product names and quarter value displayed. Now when I add the data for the Year 2015 with their product names and in the quarter, it gets added in the Year 2014 itself.

Expected o/p

ProductName         Year       Q1       Q2   Q3    Q4       Total
 BXRC-25e4000-F-04  2014       100     200   300   400       1000 
                    2015       100                            100 
                    2016       100                            100 
 BXRC-25e4000-F-23  2014       200                 200        400
                    2015       300                            300
                    2016                           200        200
 Subtotal ------------         800     200   300   800       2100


public integer previousyear{get;set;}
    public integer currentyear{get;set;}
    public integer futureyear{get;set;}
    previousyear = date.today().year()-1;
    currentyear = date.today().year();
    futureyear = date.today().year()+1;

    if ((monthText == 'Jan' || monthText == 'Feb' || monthText == 'Mar') &&(year==previousyear||year==currentyear||year==futureyear)){
                    quarterMap = Quarter1;
                    amountMap = Amount1;
                if (quarterMap.containskey(prodName)) {
                    quarterMap.put(prodName, quarterMap.get(prodName) + oppforecast.gmod__Quantity__c);
                    amountMap.put(prodName, amountMap.get(prodName) + oppforecast.gmod__Amount__c);
                } else {
                    quarterMap.put(prodName, oppforecast.gmod__Quantity__c);
                    amountMap.put(prodName, oppforecast.gmod__Amount__c);



I shall appreciate your help.

1 Answer 1


Because you are looking to group your data by product and year, your maps should be of type Map<String, Map<Integer, Decimal>> with the outer Map key as the product name (as you've got it currently) and the inner Map key as the year and the value stored the inner map is the quantity or the amount.

You might even consider nesting one more map to store the quarters and total.

    v Product   v Year       v Quarter   v Amount
Map<String, Map<Integer, Map<String, Decimal>>>
  • :i have used maps in code. i have tried giving an yearmap ut it throwed an error.Any example very much appreciated.
    – nikkey
    Commented May 6, 2015 at 16:31

You must log in to answer this question.

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