I'm getting the following email every time I update my Visual Force page.
Operation: /apex/ChurchHistoryDev
By user/organization: blah/blah
Caused the following Apex resource warnings:
Number of SOQL queries: 51 out of 100
(these emails can be disabled from the user detail page for this user)
My page displays 5 charts and has a total of 8 soql queries. I'm getting a warning about 51? /I looked at the salesforce governor help page but doesn't really give a lot of detail like most salesforce documentation. I am pretty new to salesforce development so might not be understanding this correctly. Can someone explain this?
Below is my code:
public with sharing class ChurchHistoryDevController {
public String ChurchId; // Egiving church Id
public String ChurchName;
//public Double ContribAverage;
public Date StartAvgDate;
public Date StopAvgDate;
public Date ChurchSignupDate;
public List<ChurchHist__c> ChurchData;
public ChurchHistoryDevController() {
ChurchId = ApexPages.currentPage().getParameters().get('id');
setChurchName();
// Get last 6 months of Church History
ChurchData = [Select EndOfMonth__c, ContribForMonth__c, MonthName__c, UsersForMonth__c,
AchContrib__c, CcContrib__c, ContribYTD__c
from ChurchHist__c where ChurchId__c = :ChurchId and
EndOfMonth__c >= LAST_N_MONTHS:6
order by EndOfMonth__c];
ChurchSignupDate = GetEgivingSignupDate();
StartAvgDate = ChurchSignupDate.addDays(-90);
StopAvgDate = ChurchSignupDate.addDays(90);
System.debug('Hello');
}
//*****************************************************
// Church name get and set
//*****************************************************
public void setChurchName() {
Account acct = [select Name from Account where Customer_ID__c = :ChurchId];
ChurchName = acct.Name;
}
public String getChurchName() {
return ChurchName;
}
//*****************************************************
// Egiving SignupDate
//*****************************************************
public Date GetEgivingSignupDate()
{
Account acct = [select EgSignupDate__c from Account where Customer_Id__c = :ChurchId];
return acct.EgSignupDate__c;
}
//*****************************************************
// Active members
//*****************************************************
public Decimal GetActiveMembers()
{
AggregateResult[] ch = [select max(ActiveMembers__c) Mems from ChurchHist__c where ChurchId__c = :ChurchId];
return (Decimal)ch[0].get('Mems');
}
//*****************************************************
// Church Id get
//*****************************************************
public String getChurchId() {
return ChurchId;
}
//*****************************************************
// Contrib / Month
//*****************************************************
public List<ContribData> getContribForMonthData() {
List<ContribData> cd = new List<ContribData>();
for (ChurchHist__c c : ChurchData)
{
ContribData tmp = new ContribData();
tmp.ContribForMonth = c.ContribForMonth__c;
tmp.MonthName = c.MonthName__c;
tmp.EndOfMonth = c.EndOfMonth__c;
tmp.AvgContrib = getContribAvg();
cd.add(tmp);
}
return cd;
}
public Double getContribAvg() {
Decimal members = GetActiveMembers();
AggregateResult[] ch =
[select avg(ContribForMonth__c) Average
from ChurchHist__c
where ActiveMembers__c >= :members - 50 and ActiveMembers__c <= :members + 50 and
CustomerId__r.EgSignupDate__c >= :StartAvgDate and
CustomerId__r.EgSignupDate__c <= :StopAvgDate];
//ContribAverage = (Double)ch[0].get('Average');
if (ch.size() > 0) {
return (Double)ch[0].get('Average');
} else {
return 0.0;
}
}
public class ContribData {
Double ContribForMonth { get; set; }
String MonthName { get; set; }
Date EndOfMonth { get; set; }
Double AvgContrib { get; set; }
}
//*****************************************************
// Users / Month
//*****************************************************
public List<UserForMonthData> getUsersForMonthData() {
List<UserForMonthData> UserData = new List<UserForMonthData>();
for (ChurchHist__c c : ChurchData) {
UserForMonthData tmp = new UserForMonthData();
tmp.UsersForMonth = c.UsersForMonth__c;
tmp.MonthName = c.MonthName__c;
tmp.EndOfMonth = c.EndOfMonth__c;
tmp.AvgUsersForMonth = getUserForMonthAvg();
UserData.add(tmp);
}
return UserData;
}
public Double getUserForMonthAvg() {
Decimal members = GetActiveMembers();
AggregateResult[] ch =
[select avg(UsersForMonth__c) Average
from ChurchHist__c
where ActiveMembers__c >= :members - 50 and ActiveMembers__c <= :members + 50 and
CustomerId__r.EgSignupDate__c >= :StartAvgDate and
CustomerId__r.EgSignupDate__c <= :StopAvgDate];
return (Double)ch[0].get('Average');
}
public class UserForMonthData {
Double UsersForMonth { get; set; }
String MonthName { get; set; }
Date EndOfMonth { get; set; }
Double AvgUsersForMonth { get; set; }
}
//*****************************************************
// Ach / Month
//*****************************************************
public List<AchForMonthData> getAchsForMonthData() { // achsformonthdata
List<AchForMonthData> AchData = new List<AchForMonthData>();
for (ChurchHist__c c : ChurchData) {
AchForMonthData tmp = new AchForMonthData();
tmp.AchsForMonth = c.AchContrib__c;
tmp.MonthName = c.MonthName__c;
tmp.EndOfMonth = c.EndOfMonth__c;
tmp.AvgAchsForMonth = getAchForMonthAvg();
AchData.add(tmp);
}
return AchData;
}
public Double getAchForMonthAvg() {
Decimal members = GetActiveMembers();
AggregateResult[] ch =
[select avg(AchContrib__c) Average
from ChurchHist__c
where ActiveMembers__c >= :members - 50 and ActiveMembers__c <= :members + 50 and
CustomerId__r.EgSignupDate__c >= :StartAvgDate and
CustomerId__r.EgSignupDate__c <= :StopAvgDate];
return (Double)ch[0].get('Average');
}
public class AchForMonthData {
Double AchsForMonth { get; set; }
String MonthName { get; set; }
Date EndOfMonth { get; set; }
Double AvgAchsForMonth { get; set; }
}
//*****************************************************
// CC / Month
//*****************************************************
public List<CCForMonthData> getCCsForMonthData() { // CCsformonthdata
List<CCForMonthData> CCData = new List<CCForMonthData>();
for (ChurchHist__c c : ChurchData) {
CCForMonthData tmp = new CCForMonthData();
tmp.CCsForMonth = c.CCContrib__c;
tmp.MonthName = c.MonthName__c;
tmp.EndOfMonth = c.EndOfMonth__c;
tmp.AvgCCsForMonth = getCCForMonthAvg();
CCData.add(tmp);
}
return CCData;
}
public Double getCCForMonthAvg() {
Decimal members = GetActiveMembers();
AggregateResult[] ch =
[select avg(CCContrib__c) Average
from ChurchHist__c
where ActiveMembers__c >= :members - 50 and ActiveMembers__c <= :members + 50 and
CustomerId__r.EgSignupDate__c >= :StartAvgDate and
CustomerId__r.EgSignupDate__c <= :StopAvgDate];
return (Double)ch[0].get('Average');
}
public class CCForMonthData {
Double CCsForMonth { get; set; }
String MonthName { get; set; }
Date EndOfMonth { get; set; }
Double AvgCCsForMonth { get; set; }
}
}