public with sharing class PackageBuilderExtenssion 
public PackageBuilderExtenssion(ApexPages.StandardController std) {
        id=std.getId(); //Controller Id         

        groupedResults  = [SELECT product__r.family, Sum(quantity__c)  
                           FROM package_item__c where package__c=:id
                           Group by product__r.family]; //PeiChart Result Query
public List<PieChartData> getPieData() {
        List<PieChartData> data = new List<PieChartData>();

        for (AggregateResult ar : groupedResults)  {            
                data.add(new PieChartData(
        return data;

    public class PieChartData {
        public String name { get; set; }
        public Decimal data { get; set; }
        public PieChartData(String name, Decimal data) {
            this.name = name;
            this.data = data;

closed as too broad by Reshma, Himanshu, Pranay Jaiswal, battery.cord, codeyinthecloud Jan 25 at 15:32

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Please provide more context, as your question is just a code dump. Read here on how to ask questions on SFSE. – Lukas Lunow Jan 22 at 8:13

The test class will need to:

  • insert several Product objects and several package_item__c objects related to those
  • create your controller extension as described in Testing Custom Controllers and Controller Extensions
  • invoke the getPieData method
  • assert that the number of PieChartData items and the individual field values are correct (based on the data you inserted); a clean way to do that is shown below


List<PieChartData> expecteds = new List<PieChartData>{
    new PieChartData(..., ...),
    new PieChartData(..., ...),
    new PieChartData(..., ...),
List<PieChartData> actuals = controller.getPieData();
System.assertEquals(expecteds, actuals);

Not the answer you're looking for? Browse other questions tagged or ask your own question.