You need to sign in to do that
Don't have an account?

Get method with SOQL query not working
I have a visualforce page to display some basic account data. The page uses the standard Account controller with a custom extension. Basically I just want the page to display the sum of all the related donations (Donation__c) via {!TotalDonations }.
My custom controller is intended to get this information using a get method and SOQL query but I just can’t get it to work. I’ve tried several variations of code but have been unsuccessful. If anyone can help point me in the right direction it would be greatly appreciated.
public with sharing class MyTabbedExtension {
public MyTabbedExtension(ApexPages.StandardController controller) {
}
public integer totaldonations(){
return database.query(SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID'));
}
// THIS WAS JUST ANOTHER ATTEMPT THAT DID NOT WORK
Public list <Donation__c> getTotalDonations(){
return totalDonations = [SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID')];
}
}
My custom controller is intended to get this information using a get method and SOQL query but I just can’t get it to work. I’ve tried several variations of code but have been unsuccessful. If anyone can help point me in the right direction it would be greatly appreciated.
public with sharing class MyTabbedExtension {
public MyTabbedExtension(ApexPages.StandardController controller) {
}
public integer totaldonations(){
return database.query(SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID'));
}
// THIS WAS JUST ANOTHER ATTEMPT THAT DID NOT WORK
Public list <Donation__c> getTotalDonations(){
return totalDonations = [SELECT Sum(Donation_Amount__c) FROM Donation__c WHERE Parent_Account__c = :ApexPages.currentPage().getParameters().get('ID')];
}
}
Please remove all methods and add the below mention method :
Let me know if you face any issue with this.
Regards,
Abhishek Bansal.
All Answers
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_agg_functions.htm
This document will give you the details about SOQL aggregate functions. Please go through it. If you didn't get answer, please paste your VF page code here.
Please remove all methods and add the below mention method :
Let me know if you face any issue with this.
Regards,
Abhishek Bansal.