Skip to main content
Hi,

I can't seem to figure this out.  I have two try blocks.  With the first one, the query is working as reflected by the sytem.debug inside the try block.  But outside the try block, the variable is showing as zero.  However the subsequent try block seems to be passing data out just fine.

What am I doing wrong?

Thanks,

 

public class PersonalDashBoardClass {

// attributes come first

public My_Plan__c myPlan;

User currentUser;

String userId;

Integer revenueMax =0;

Integer marginMax = 0;

Integer totalRevenue = 0;

Integer totalMargin = 0;

//Constructor comes next

public PersonalDashBoardClass(ApexPages.StandardController stdController) {

this.myPlan = (My_Plan__c)stdController.getRecord();

currentUser = [Select id from User where id =: UserInfo.getUserId() LIMIT 1];

userId = currentUser.id;

// get the revenue and margin goals from the Goals__C object

try {

Goals__c myGoal = [SELECT Revenue_Goal__C, Margin_Goal__C FROM Goals__c WHERE OwnerId =:UserId AND Start_Date_of_New_Quarter__c = THIS_Quarter LIMIT 1];

Integer revenueMax = (Integer)myGoal.Revenue_Goal__c/1000;

Integer marginMax = (Integer)myGoal.Margin_Goal__c/1000;

System.debug ('the total revenue in the try block is ' + revenueMax);

} catch (exception e) {

system.debug(e);

ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'You must have a goal for the quarter'));

system.debug(' you have an error' +e);

}

// get the total revenue and total margin for closed opportunities for this quarter

try {

AggregateResult ClosedWonOpptys = [select SUM(Amount) totalRevenue, CALENDAR_QUARTER(CloseDate) theMonth, COUNT(Name) numOpps

from Opportunity

where (OwnerId =: UserId OR

Account.Client_Specialist_1__c =:UserId OR

Account.Client_Specialist_2__c =:UserId OR

Account.Client_Executive__c =:UserId)

AND CloseDate = THIS_Quarter

GROUP BY CALENDAR_QUARTER(CloseDate) LIMIT 1];

totalRevenue = Integer.valueOf(closedWonOpptys.get('totalRevenue'))/1000;

} catch (exception e) {

}

system.debug('total revenue = '+totalRevenue + ' and max revenue is ' +revenueMax);

}

public Integer guageChartRevenue {

get {

return totalRevenue;

} set;

}

public Integer guageMaxRevenue {

get {

return revenueMax;

} set;

}

}

 
1 answer
  1. Feb 16, 2015, 7:28 PM
    Ok, I found the problem.  I was reinializing the revenueMax and MarginMax as integer's inside the try block.  That gave them local scope, and then after the constructor they went back to zero.

    Couple hours wasted for a simple mistake, lol

    Thanks,
0/9000