I'm creating a VF pie chart where I need to display formula type field. I'm able to display the chart if using a picklist type field. However I need to display the chart using a formula type field. In my code, instead of 'Order_Type__c' (picklist field) I need to use a formula type field. Here is my code.

Page <apex:sectionHeader subtitle="Pie Chart "/> <apex:chart height="200" width="400" data="{!positionCountData}"> <apex:pieSeries dataField="posCount" labelField="Category"/> <apex:legend position="right"/> </apex:chart>


 public List<PositionData> getPositionCountData ()  {
   // SOQL query to get the count of positions by its functional area
List<AggregateResult> countdata = [select Sum(Amount__c) cnt,Order_Type__c
             from Transaction__c
             group by Order_Type__c];
           //  order by Category__c];
        list<SelectOption> options = new list<SelectOption>();

         // PickListController is used to get values from picklist since Functional area has datatype as picklist
                      options = PickListController.getPicklistValues(new Transaction__c (),'Order_Type__c');
  // Position data is stored in a list    
                       List<PositionData> posList = new List<PositionData>();
                       PositionData pos;
                        Integer j=0;
                       for (Integer i=0; i<options.size(); i++) {
                              pos = new PositionData();
                              String CatList = '';
                              String CatPickList = null;
                              if(i!=0) {
                                             CatPickList = options[i-1].getLabel();
                                 if(j < countdata.size()){
                                    CatList = String.valueOf(countdata[j].get('Order_Type__c'));

                              if(CatPickList == CatList) {
                                     pos.posCount = Double.valueOf(countdata[j].get('cnt'));
                                    pos.Category = String.valueOf(countdata[j].get('Order_Type__c'));
                                     pos.Category = CatPickList;
                                    pos.posCount = 0;
                                     pos.Category = CatPickList;
  // In case there are positions without any specific functional area they are grouped under “Others”
                      if(i==0) {
                          pos.Category = '';
            return posList; 
  // Wrapper class for Pie Chart 
   public class PositionData { 
                 public Double posCount; 
                 public String Category;

1 Answer 1


According to the documentation


"Some object fields have a field type that does not support grouping. You can't include fields with these field types in a GROUP BY clause. The Field object associated with DescribeSObjectResult has a groupable field that defines whether you can include the field in a GROUP BY clause."

So you may not be able to run your query using a formula field as the group-by.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .