Skip to main content
Hi,

I had a guage chart where the goal was an integer number.  This worked fine, until I hooked it up to an object which returns a decimal. I've tried turning the decimal into an integer using "Integer.valueOf()", but my chart ends up blank when I do this.

Any ideas?

Thanks,

 

public class AccountChartClass {

// get the user id so that the data is only for the current user

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

String UserID = u.id;

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

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];

// Integer revenueMax = 1000000/1000; // this works, but I need it to pull from from the query

Integer revenueMax = Integer.valueOf(myGoal.Revenue_Goal__c); // this doesn't work

Integer marginMax = 300000/1000;

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

// Return a list of data points for a revenue guage chart

public List<Data> getGuageChartRevenue() {

Integer TotalOpptys = 0;

Integer TotalAmount = 0;

Integer thisMonth = date.Today().month();

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

from Opportunity

where OwnerId =: UserId AND CloseDate = THIS_Quarter

GROUP BY CALENDAR_MONTH(CloseDate) LIMIT 1];

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

List<Data> ChartData1 = new List<Data>();

ChartData1.add(new Data('Total' + ' Opptys', totalRevenue ) );

return ChartData1;

}

// returns the guage revenue max

public Integer GuageMaxRev {

get {

return revenueMax;

} set;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

// Return a list of data points for a margin guage chart

public List<Data> getGuageChartmargin() {

Integer TotalOpptys = 0;

Integer TotalAmount = 0;

Integer thisMonth = date.Today().month();

AggregateResult ClosedWonOpptys = [select SUM(Total_Gross_Margin__c) totalMargin, CALENDAR_MONTH(CloseDate) theMonth, COUNT(Name) numOpps

from Opportunity

where OwnerId =: UserId AND CloseDate = THIS_Quarter

GROUP BY CALENDAR_MONTH(CloseDate) LIMIT 1];

double totalMargin = double.valueOf(closedWonOpptys.get('totalMargin'))/1000;

List<Data> ChartData1 = new List<Data>();

ChartData1.add(new Data('Total' + ' Opptys', totalMargin ) );

return ChartData1;

}

// returns the guage revenue max

public Integer GuageMaxMargin {

get {

return marginMax;

} set;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

// Return a list of data points for a chart

public List<Data> getTypeChart() {

List<Data> ChartData2 = new List<Data>();

List<AggregateResult> getList= [SELECT Type, SUM(Amount) data1 FROM Opportunity

WHERE Opportunity.OwnerId=:UserId AND CloseDate = THIS_Quarter

GROUP BY Type ];

for(AggregateResult opp :getList) {

String oppName = String.valueOf(opp.get('Type'));

double oppPrice = Integer.valueOf(opp.get('data1'));

ChartData2.add(new Data(oppName, oppPrice));

}

System.debug(ChartData2);

return ChartData2;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Wrapper class

public class Data {

public String name { get; set; }

public Double data1 { get; set; }

public Data(String name, Double data1) {

this.name = name;

this.data1 = data1;

}

}

/////////////////////////////////////////////////////////////////////////////

public list<Opportunity> getOppList90() {

List<Opportunity> OppList = new List<Opportunity>();

OppList = [SELECT Account.Name, Name, CloseDate, Amount

FROM Opportunity

WHERE Opportunity.OwnerId=:UserId AND StageName='A. Pending Sale' AND CloseDate = THIS_Quarter

ORDER BY Amount DESC LIMIT 10];

return OppList;

}

public Opportunity getOpp90Total() {

Opportunity opp90Total = new Opportunity(Amount=0);

for(Opportunity o :getOppList90()) {

opp90Total.Amount +=o.amount;

}

return opp90Total;

}

///////////////////////////////////////////////////////////////////////////

public class AcctSumList {

public String AccountName {get; set; }

public double AccountTotal {get; set; }

public AcctSumList(String AccountName, double AccountTotal) {

this.AccountName = AccountName;

this.AccountTotal = AccountTotal;

}

}

/////////////////////////////////////////////////////////////////////////

public List<AcctSumList> getAccountSummary90() {

list<AcctSumList> acctSummary = new List<AcctSumList>();

List<AggregateResult> getList = [SELECT Account.Name acctName, sum(amount) TotalAmount

FROM Opportunity

WHERE Opportunity.OwnerId=:UserId AND StageName='A. Pending Sale' AND CloseDate = THIS_Quarter

GROUP BY Account.Name ORDER BY sum(amount) DESC LIMIT 10];

for(AggregateResult agg : getList) {

String AccountName = (string)agg.get('acctName');

Double TotalAmount = (double)agg.get('TotalAmount');

acctSummary.add(new AcctSumList(AccountName, TotalAmount));

}

return acctSummary;

}

public double getAcct90Total() {

double Acct90Total = 0;

for(AcctSumList acct :getAccountSummary90()) {

Acct90Total += acct.AccountTotal;

}

return Acct90Total;

}

///////////////////////////////////////////////////////////////////////////

public list<Opportunity> getOppList60() {

List<Opportunity> OppList = new List<Opportunity>();

OppList = [SELECT Account.Name, Name, CloseDate, Amount

FROM Opportunity

WHERE Opportunity.OwnerId=:UserId AND StageName='B. Decision Due' AND CloseDate = THIS_Quarter

ORDER BY Amount DESC LIMIT 10];

return OppList;

}

public Opportunity getOpp60Total() {

Opportunity opp60Total = new Opportunity(Amount=0);

for(Opportunity o :getOppList60()) {

opp60Total.Amount +=o.amount;

}

return opp60Total;

}

/////////////////////////////////////////////////////////////////////////

public List<AcctSumList> getAccountSummary60() {

list<AcctSumList> acctSummary = new List<AcctSumList>();

List<AggregateResult> getList = [SELECT Account.Name acctName, sum(amount) TotalAmount

FROM Opportunity

WHERE Opportunity.OwnerId=:UserId AND StageName='B. Decision Due' AND CloseDate = THIS_Quarter

GROUP BY Account.Name ORDER BY sum(amount) DESC LIMIT 10];

for(AggregateResult agg : getList) {

String AccountName = (string)agg.get('acctName');

Double TotalAmount = (double)agg.get('TotalAmount');

acctSummary.add(new AcctSumList(AccountName, TotalAmount));

}

return acctSummary;

}

public double getAcct60Total() {

double Acct60Total = 0;

for(AcctSumList acct :getAccountSummary60()) {

Acct60Total += acct.AccountTotal;

}

return Acct60Total;

}

}

 
1 réponse
0/9000