The code below is working so far.
Now I added two fields to the visualforce page (selected_year_1 selected_year_2) where the user can select a year (2016/2017/2018...) for both fields. This years should loop thru my code below. At the end I should have 24 values. I tried a bit with the following code, but I don't know to keep the values, because the years loop thru but overwrite my values from the first loop.
Integer[] arrayOfYear = new List<Integer>();
//Adding elements in Array
arrayOfYear.add(Selected_Year_1);
arrayOfYear.add(Selected_Year_2);
for (Integer j = 0; j<arrayOfYear.size(); j++) {
//This loop will print all the elements in array
system.debug('Values In Array: '+arrayOfYear[j]);
}
How can I keep all values in seperate variables?
public void getData(){
String SelectClause = 'SELECT BWS__c, Date__c FROM Sales__c';
List <String> WhereClauses = new List <String>();
IF (SelectedUserId != ('North') && SelectedUserId != ('South') && SelectedUserId != ('East') && SelectedUserId != ('West') && SelectedUserId != Null) {
WhereClauses.Add('Salesman__r.Id = \'' + SelectedUserId + '\'');
}
IF (SelectedUserId == ('')) {
WhereClauses.Add('');
}
WhereClauses.Add('BWS__c != NULL AND Calendar_Year(Date__c) = ' + Selected_Year_1);
String WhereClause = ' WHERE ' + String.join(WhereClauses, ' AND ');
String SQL = SelectClause + WhereClause;
List <Sales__c> SalesList = Database.query(SQL);
Decimal[] values = new Decimal[12];
FOR(Integer i = 0; i < values.size(); i++)
{ values[i] = 0; }
FOR(Sales__c Sales : SalesList)
{
Integer Mo = Sales.Date__c.month();
values[Mo-1] += Sales.BWS__c;
}
Y1_01_BWS = values[0];
Y1_02_BWS = values[1];
Y1_03_BWS = values[2];
Y1_04_BWS = values[3];
Y1_05_BWS = values[4];
Y1_06_BWS = values[5];
Y1_07_BWS = values[6];
Y1_08_BWS = values[7];
Y1_09_BWS = values[8];
Y1_10_BWS = values[9];
Y1_11_BWS = values[10];
Y1_12_BWS = values[11];
}
EDIT
I found this snippet, but it's the same problem. I have specific values. I thoght that I run the aggregate and transfer the values to the google line chart. But how can I the both selected years with the 12 values of month.
List<AggregateResult> aggList =[Select Attendence_Status__c,Count(Id) FROM Attendance__c WHERE Enrollment__r.Student__c=:contactId GROUP BY Attendence_Status__c];
for(AggregateResult aggResult:aggList){
if(aggResult.get('Attendence_Status__c')=='Partially Attended'){
partialCount= (Integer)aggResult.get('expr0');
}else if(aggResult.get('Attendence_Status__c')=='Attended'){
attendedCount = (Integer)aggResult.get('expr0');
}else if(aggResult.get('Attendence_Status__c')=='Absent'){
absentCount= (Integer)aggResult.get('expr0');
}