You need to sign in to do that
Don't have an account?
Radhika pawar 5
addition of two integer value divide by another integer value outputcomes in decimal for Controller
I have one Error for Illegal assignment from Decimal to Integer at line 178 column 13
List<Integer> total = new List<Integer>();
table in that SR.No(Serial No) ,Number of villages reached,Govt Schools,Pvt Schools,Other Schools,Avg other schools in the Pratham intervention areas columns.
Example: this are Column
SRNO. (Number of villages reached) (Govt Schools ) (Pvt Schools) (Other Schools) (Avg other schools in the Pratham intervention areas)
1 4 1 2 3 3+2+1/4=1.5
I want 1.5 values in last column name is Other Schools Avg other schools in the Pratham intervention areas.
but my out put comes 1 in integer .
please guide me.
My code is this:
public with sharing class ctrl_RI14_other_school_trends {
public List<SelectOption> lstNational {get;set;}
public List<SelectOption> lstPhase {get;set;}
//public List<SelectOption> lstDonor = new List<SelectOption>();
public List<RI_School_Report_Cards__c> lstSchool = new List<RI_School_Report_Cards__c>();
public List<Report> lstwrap1Sub {get;set;}
public String strState {get;set;}
public String strBlocks {get;set;}
public String strNational {get;set;}
public String strSchool {get;set;}
public String strPhase {get;set;}
// public String strDonor {get;set;}
public ctrl_RI14_other_school_trends()
{
strState = '';
strBlocks = '';
strNational = '' ;
strSchool = '';
strPhase = '';
// strDonor = '';
lstPhase = new List<SelectOption>();
lstPhase.add(new SelectOption('', '- - None - -'));
Schema.DescribeFieldResult F = RI_School_Report_Cards__c.BCI_CP_P_NO__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues())
{
lstPhase.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstNational = new List<SelectOption>();
lstNational.add(new SelectOption('', '- - None - -'));
F = RI_School_List__c.National__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues())
{
lstNational.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstwrap1Sub = new List<Report>();
}
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_School_Report_Cards__c where Submission_No__c != null AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBlocks() {
List<SelectOption> lstSchoolBlocks = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.block__c block from RI_School_Report_Cards__c where Submission_No__c != null AND School_List__r.state__c =: strState AND School_List__r.National__c =: strNational GROUP BY School_List__r.block__c ];
lstSchoolBlocks.add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolBlocks.add(new SelectOption(String.valueOf(temp.get('block')),String.valueOf(temp.get('block'))));
}
return lstSchoolBlocks;
}
public List<SelectOption> getAttSchool() {
List<SelectOption> lstSchools = new List<SelectOption>();
List<RI_School_Report_Cards__c> lst = [Select School_List__r.Name, school_list__c, school_list__r.School__c from RI_School_Report_Cards__c where Submission_No__c != null AND Submit_Camp_4__c = true AND School_List__r.state__c =: strState AND School_List__r.National__c =: strNational AND school_list__r.block__c =: strBlocks];
lstSchools.add(new SelectOption('','-None-'));
for(RI_School_Report_Cards__c temp: lst) {
lstSchools.add(new SelectOption(temp.school_list__c, temp.school_list__r.school__c + ' : ' + temp.school_list__r.Name));
}
return lstSchools;
}
public pagereference loadReport()
{
lstwrap1Sub.clear();
String query = 'SELECT COUNT(School_List__r.Village__c) reached,SUM(MI_TL_Gov_SL__c) GOV_SL, SUM(MI_TL_Pvt_SL__c) PVT_SL, SUM(MI_TL_Other_SL__c) Other_SL';
if (strState == '' || strState == null)
{
query += ', School_List__r.State__c grouper';
}
else if(strBlocks == '' || strBlocks == null)
{
query += ', School_List__r.block__c grouper';
}
else
{
if(strSchool == '' || strSchool == null)
{
query += ', School_List__r.block__c grouper';
}
else
{
query += ', School_List__r.Name grouper';
}
}
query += ' FROM RI_School_Report_Cards__c WHERE School_List__r.National__c =: strNational AND Submission_No__c != null ';
if (strState != '' && strState != null) {
query += ' AND school_list__r.state__c =: strState';
}
if(strBlocks != '' && strBlocks != null) {
query += ' AND school_list__r.block__c =: strBlocks';
}
if(strSchool != '' && strSchool != null) {
query += ' AND school_list__c =: strSchool';
}
if(strPhase != '' && strPhase != null) {
query += ' AND BCI_CP_P_NO__c =: strPhase';
}
if (strState == '' || strState == null) {
query += ' GROUP BY School_List__r.State__c';
}
else if (strBlocks == '' || strBlocks == null)
{
query += ' GROUP BY School_List__r.block__c';
}
else
{
if(strSchool == '' || strSchool == null)
{query += ' GROUP BY School_List__r.block__c';}
else
{query += ' GROUP BY School_List__r.Name ';}
}
AggregateResult []ar = Database.query(query);
Map <String, Integer> reach = new Map<String, Integer>();
Map <String, Integer> GOV = new Map<String, Integer>();
Map <String, Integer> PVT = new Map<String, Integer>();
Map <String, Integer> Other = new Map<String, Integer>();
for (AggregateResult temp : ar)
{
if(Integer.valueOf(temp.get('reached')) !=0)
{
reach.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('reached')));
}
GOV.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('GOV_SL')));
PVT.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('PVT_SL')));
Other.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('Other_SL')));
}
Integer i = 1;
for(AggregateResult temp : ar)
{
lstwrap1Sub.add(new Report(i, String.valueOf(temp.get('grouper')), reach.get(String.valueOf(temp.get('grouper'))), GOV.get(String.valueOf(temp.get('grouper'))), PVT.get(String.valueOf(temp.get('grouper'))),Other.get(String.valueOf(temp.get('grouper'))),
((GOV.get(String.valueOf(temp.get('grouper')))+ PVT.get(String.valueOf(temp.get('grouper')))+ Other.get(String.valueOf(temp.get('grouper'))) )/reach.get(String.valueOf(temp.get('grouper')))) ));
i++;
}
List<Integer> total = new List<Integer>();
total.add(0);
total.add(0);
total.add(0);
total.add(0);
total.add(0);
if (strBlocks == '' || strBlocks == null) {
for(Report temp : lstwrap1Sub)
{
total[0] += temp.reached;
total[1] += temp.GOV_SL;
total[2] += temp.PVT_SL;
total[3] += temp.Other_SL;
total[4] += temp.avg;
}
lstwrap1Sub.add(new Report(null, 'Total', total[0], total[1], total[2], total[3], total[4]));
}
return null;
}
class Report
{
public Integer reached {get;set;}
public String grouper {get;set;}
public Integer sr_no {get;set;}
public Integer GOV_SL{get;set;}
public Integer PVT_SL{get;set;}
public Integer Other_SL{get;set;}
public Integer avg {get;set;}
public Report(Integer sr_no,String grouper,Integer reached,Integer GOVSL,Integer PVTSL,Integer other,Integer avg_gpo )
{
this.grouper = grouper;
this.sr_no = sr_no;
this.reached = reached == null ? 0 : reached;
this.GOV_SL = GOVSL == null ? 0 : GOVSL;
this.PVT_SL = PVTSL== null ? 0 : PVTSL;
this.Other_SL = other== null ? 0 : other;
this.avg = avg_gpo == null ? 0 :avg_gpo;
}
}
}
List<Integer> total = new List<Integer>();
table in that SR.No(Serial No) ,Number of villages reached,Govt Schools,Pvt Schools,Other Schools,Avg other schools in the Pratham intervention areas columns.
Example: this are Column
SRNO. (Number of villages reached) (Govt Schools ) (Pvt Schools) (Other Schools) (Avg other schools in the Pratham intervention areas)
1 4 1 2 3 3+2+1/4=1.5
I want 1.5 values in last column name is Other Schools Avg other schools in the Pratham intervention areas.
but my out put comes 1 in integer .
please guide me.
My code is this:
public with sharing class ctrl_RI14_other_school_trends {
public List<SelectOption> lstNational {get;set;}
public List<SelectOption> lstPhase {get;set;}
//public List<SelectOption> lstDonor = new List<SelectOption>();
public List<RI_School_Report_Cards__c> lstSchool = new List<RI_School_Report_Cards__c>();
public List<Report> lstwrap1Sub {get;set;}
public String strState {get;set;}
public String strBlocks {get;set;}
public String strNational {get;set;}
public String strSchool {get;set;}
public String strPhase {get;set;}
// public String strDonor {get;set;}
public ctrl_RI14_other_school_trends()
{
strState = '';
strBlocks = '';
strNational = '' ;
strSchool = '';
strPhase = '';
// strDonor = '';
lstPhase = new List<SelectOption>();
lstPhase.add(new SelectOption('', '- - None - -'));
Schema.DescribeFieldResult F = RI_School_Report_Cards__c.BCI_CP_P_NO__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues())
{
lstPhase.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstNational = new List<SelectOption>();
lstNational.add(new SelectOption('', '- - None - -'));
F = RI_School_List__c.National__c.getDescribe();
for (Schema.PicklistEntry temp : F.getPicklistValues())
{
lstNational.add(new SelectOption(temp.getValue(), temp.getLabel()));
}
lstwrap1Sub = new List<Report>();
}
public List<SelectOption> getAttStates() {
List<SelectOption>lstSchoolStates = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.State__c State from RI_School_Report_Cards__c where Submission_No__c != null AND School_List__r.National__c =: strNational GROUP BY School_List__r.State__c];
lstSchoolStates .add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolStates.add(new SelectOption(String.valueOf(temp.get('State')),String.valueOf(temp.get('State'))));
}
return lstSchoolStates ;
}
public List<SelectOption> getAttBlocks() {
List<SelectOption> lstSchoolBlocks = new List<SelectOption>();
AggregateResult []ar = [Select School_List__r.block__c block from RI_School_Report_Cards__c where Submission_No__c != null AND School_List__r.state__c =: strState AND School_List__r.National__c =: strNational GROUP BY School_List__r.block__c ];
lstSchoolBlocks.add(new SelectOption('','-None-'));
for(AggregateResult temp: ar) {
lstSchoolBlocks.add(new SelectOption(String.valueOf(temp.get('block')),String.valueOf(temp.get('block'))));
}
return lstSchoolBlocks;
}
public List<SelectOption> getAttSchool() {
List<SelectOption> lstSchools = new List<SelectOption>();
List<RI_School_Report_Cards__c> lst = [Select School_List__r.Name, school_list__c, school_list__r.School__c from RI_School_Report_Cards__c where Submission_No__c != null AND Submit_Camp_4__c = true AND School_List__r.state__c =: strState AND School_List__r.National__c =: strNational AND school_list__r.block__c =: strBlocks];
lstSchools.add(new SelectOption('','-None-'));
for(RI_School_Report_Cards__c temp: lst) {
lstSchools.add(new SelectOption(temp.school_list__c, temp.school_list__r.school__c + ' : ' + temp.school_list__r.Name));
}
return lstSchools;
}
public pagereference loadReport()
{
lstwrap1Sub.clear();
String query = 'SELECT COUNT(School_List__r.Village__c) reached,SUM(MI_TL_Gov_SL__c) GOV_SL, SUM(MI_TL_Pvt_SL__c) PVT_SL, SUM(MI_TL_Other_SL__c) Other_SL';
if (strState == '' || strState == null)
{
query += ', School_List__r.State__c grouper';
}
else if(strBlocks == '' || strBlocks == null)
{
query += ', School_List__r.block__c grouper';
}
else
{
if(strSchool == '' || strSchool == null)
{
query += ', School_List__r.block__c grouper';
}
else
{
query += ', School_List__r.Name grouper';
}
}
query += ' FROM RI_School_Report_Cards__c WHERE School_List__r.National__c =: strNational AND Submission_No__c != null ';
if (strState != '' && strState != null) {
query += ' AND school_list__r.state__c =: strState';
}
if(strBlocks != '' && strBlocks != null) {
query += ' AND school_list__r.block__c =: strBlocks';
}
if(strSchool != '' && strSchool != null) {
query += ' AND school_list__c =: strSchool';
}
if(strPhase != '' && strPhase != null) {
query += ' AND BCI_CP_P_NO__c =: strPhase';
}
if (strState == '' || strState == null) {
query += ' GROUP BY School_List__r.State__c';
}
else if (strBlocks == '' || strBlocks == null)
{
query += ' GROUP BY School_List__r.block__c';
}
else
{
if(strSchool == '' || strSchool == null)
{query += ' GROUP BY School_List__r.block__c';}
else
{query += ' GROUP BY School_List__r.Name ';}
}
AggregateResult []ar = Database.query(query);
Map <String, Integer> reach = new Map<String, Integer>();
Map <String, Integer> GOV = new Map<String, Integer>();
Map <String, Integer> PVT = new Map<String, Integer>();
Map <String, Integer> Other = new Map<String, Integer>();
for (AggregateResult temp : ar)
{
if(Integer.valueOf(temp.get('reached')) !=0)
{
reach.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('reached')));
}
GOV.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('GOV_SL')));
PVT.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('PVT_SL')));
Other.put(String.valueOf(temp.get('grouper')), Integer.valueOf(temp.get('Other_SL')));
}
Integer i = 1;
for(AggregateResult temp : ar)
{
lstwrap1Sub.add(new Report(i, String.valueOf(temp.get('grouper')), reach.get(String.valueOf(temp.get('grouper'))), GOV.get(String.valueOf(temp.get('grouper'))), PVT.get(String.valueOf(temp.get('grouper'))),Other.get(String.valueOf(temp.get('grouper'))),
((GOV.get(String.valueOf(temp.get('grouper')))+ PVT.get(String.valueOf(temp.get('grouper')))+ Other.get(String.valueOf(temp.get('grouper'))) )/reach.get(String.valueOf(temp.get('grouper')))) ));
i++;
}
List<Integer> total = new List<Integer>();
total.add(0);
total.add(0);
total.add(0);
total.add(0);
total.add(0);
if (strBlocks == '' || strBlocks == null) {
for(Report temp : lstwrap1Sub)
{
total[0] += temp.reached;
total[1] += temp.GOV_SL;
total[2] += temp.PVT_SL;
total[3] += temp.Other_SL;
total[4] += temp.avg;
}
lstwrap1Sub.add(new Report(null, 'Total', total[0], total[1], total[2], total[3], total[4]));
}
return null;
}
class Report
{
public Integer reached {get;set;}
public String grouper {get;set;}
public Integer sr_no {get;set;}
public Integer GOV_SL{get;set;}
public Integer PVT_SL{get;set;}
public Integer Other_SL{get;set;}
public Integer avg {get;set;}
public Report(Integer sr_no,String grouper,Integer reached,Integer GOVSL,Integer PVTSL,Integer other,Integer avg_gpo )
{
this.grouper = grouper;
this.sr_no = sr_no;
this.reached = reached == null ? 0 : reached;
this.GOV_SL = GOVSL == null ? 0 : GOVSL;
this.PVT_SL = PVTSL== null ? 0 : PVTSL;
this.Other_SL = other== null ? 0 : other;
this.avg = avg_gpo == null ? 0 :avg_gpo;
}
}
}
Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
PLease guide me in controller.
Integer i=2;
Integer j=4;
Integer k=7;
Then you can write like.
double d = (double)(i+j/k);
you can read here :
http://peterknolle.com/calculations-in-apex/
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_decimal.htm