function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NVaefNVaef 

Using Multiple Extensions Problem

I'm reposting this because I never got a response - sorry.

 

I've set up 3 charts with 3 seperate controllers on a visual force page, however the information on all of the charts is being rendered the same for all three based on the last extension being used in the VF order. 

 

Initially I thought it was the data variable being consistent through each controller, but no matter how I changed or manipulated it, it didn't work. I figure that regardless of the data variable it should be different per each controller. 

 

Any insight would be greatly appreciated, thank you!

 

VF:

 

<apex:tab label="Gauge Party" rendered="{!Events__c.Meeting_Type__c <> 'Argyle Conversation'}" name="GaugeParty" id="tabGauges">
<apex:pageBlock title="{!$ObjectType.Events__c.label} Gauge">
<apex:pageBlockSection showHeader="true" title="Attendee Goal" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController">
<apex:chart name="MyChart" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attendee Goal" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
</apex:page>
</apex:pageBlockSection>
<apex:pageBlockSection showHeader="true" title="Attended" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController2">
<apex:chart name="MyChart2" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attended" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart2.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
</apex:page>
</apex:pageBlockSection>
<apex:pageBlockSection showHeader="true" title="Confirmed" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController3">
<apex:chart name="MyChart3" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Confirmed" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart3.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
</apex:page>
</apex:pageBlockSection>
</apex:pageBlock>

Best Answer chosen by Admin (Salesforce Developers) 
ForcepowerForcepower

try this:

 

public class GaugeChartController {
    public String ProjId {get;set;}
    public Attendee_Project_Junction__c dummyAPJ {get;set;}

    public List<gaugeData> data {get;set;}

 

 

Change your getData to this:

 

public PageReference getData() {
          Integer TotalAttnds = 0;

         data = new List<gaugeData>();       
         String attendeeStatus = dummyAPJ.Attendance_Status__c;
         AggregateResult[] AttendeeList;

 

All Answers

bob_buzzardbob_buzzard

I suspect its because you have multiple <apex:page /> components in there.  From the docs:

 

--- snip ---

 

A single Visualforce page. All pages must be wrapped inside a single page component tag. 

 

--- snip ---

 

 

NVaefNVaef

Initially, I had them stacked - I ended up putting them in separate pages and page blocks in order to try and separate the data. 

ForcepowerForcepower

NV,

 

May I ask how exactly you are using these three pages - are they part of a wizard? Or just three different views of your data?

 

Best,

Ram

NVaefNVaef

They're different views of data. It's a cloned controller, renamed and such, with filters to pull specific attendee statuses. I know each of them works because I tried cycling the controllers.

ForcepowerForcepower

NV,

 

You may want to post your controller code for the three controller extensions. Your VF pages (judging by the the combined page you posted earlier) seem identical.

 

Ram

NVaefNVaef

First one:

public class GaugeChartController {
    public String ProjId {get;set;}
 
    public GaugeChartController(ApexPages.StandardController controller){
        ProjId = controller.getRecord().Id;
    }
 
    public List<gaugeData> getData() {
          Integer TotalAttnds = 0;List<gaugeData> data = new List<gaugeData>();       
 
         AggregateResult[] AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId                                
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
                                   
if (!attendeeList.isEmpty())
{
    //Do logic with the items in the list
        data.add(new gaugeData('Attendees', Integer.valueOf(attendeeList[0].get('numAPJs'))));   
}
else
        data.add(new gaugeData('Attendees', 0));                              
   

          return data;
                                       
     }
 
    public class gaugeData {
        public String name { get; set; }
        public Integer size { get; set; }
 
        public gaugeData(String name, Integer data) {
            this.name = name;
            this.size = data;
        }
    }
}

 

Second one:

public class GaugeChartController2 {
    public String ProjId {get;set;}
 
    public GaugeChartController2(ApexPages.StandardController controller){
        ProjId = controller.getRecord().Id;
    }
 
    public List<gaugeData> getData() {
          Integer TotalAttnds = 0;List<gaugeData> data = new List<gaugeData>();       
 
         AggregateResult[] AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c                                    
                                   where Project__c =: projId 
                                   and Attendance_Status__c = 'Attended'                               
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
                                   
if (!attendeeList.isEmpty())
{
    //Do logic with the items in the list
        data.add(new gaugeData('Attendees', Integer.valueOf(attendeeList[0].get('numAPJs'))));   
}
else
        data.add(new gaugeData('Attendees', 0));                              
   

          return data;
                                       
     }
 
    public class gaugeData {
        public String name { get; set; }
        public Integer size { get; set; }
 
        public gaugeData(String name, Integer data) {
            this.name = name;
            this.size = data;
        }
    }
}

 

third one:

public class GaugeChartController3 {
    public String ProjId {get;set;}
 
    public GaugeChartController3(ApexPages.StandardController controller){
        ProjId = controller.getRecord().Id;
    }
 
    public List<gaugeData> getData() {
          Integer TotalAttnds = 0;List<gaugeData> data = new List<gaugeData>();       
 
         AggregateResult[] AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId
                                   and Attendance_Status__c = 'Confirmed'                                
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
                                   
if (!attendeeList.isEmpty())
{
    //Do logic with the items in the list
        data.add(new gaugeData('Attendees', Integer.valueOf(attendeeList[0].get('numAPJs'))));   
}
else
        data.add(new gaugeData('Attendees', 0));                              
   

          return data;
                                       
     }
 
    public class gaugeData {
        public String name { get; set; }
        public Integer size { get; set; }
 
        public gaugeData(String name, Integer data) {
            this.name = name;
            this.size = data;
        }
    }
}

ForcepowerForcepower

NV,

 

Is Attendance_Status__c a picklist?

 

Ram

ForcepowerForcepower

NV,

Here's what I would recommend - rather than using three different controllers, you can achieve your goal with one (doesn't necessarily address your issue with multiple controllers but eliminates the need for them). I'm assuming Attendance_Status__c is a picklist.

// VF Code ****************************** add this into your form - this should allow selection of ALL, Attended, Confirmed etc

<apex:inputField value="{!dummyAPJ.Attendance_Status__c}" />

 

// Controller code **********************************************

public class GaugeChartController {
    public String ProjId {get;set;}
    public Attendee_Project_Junction__c dummyAPJ {get;set;}
    public GaugeChartController(ApexPages.Standard

Controller controller){
        ProjId = controller.getRecord().Id;

        dummyAPJ = new Attendee_Project_Junction__c();
    }
 
    public List<gaugeData> getData() {
          Integer TotalAttnds = 0;List<gaugeData> data = new List<gaugeData>();       
         String attendeeStatus = dummyAPJ.Attendance_Status__c;
         AggregateResult[] AttendeeList;

         if (attendeeStatus == 'ALL') {

         AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId                                
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
          }

         else {

         AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId                                

                                   and Attendance_Status__c = :attendeeStatus
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];

         }                      
if (!attendeeList.isEmpty())
{
    //Do logic with the items in the list
        data.add(new gaugeData('Attendees', Integer.valueOf(attendeeList[0].get('numAPJs'))));   
}
else
        data.add(new gaugeData('Attendees', 0));                              
   

          return data;
                                       
     }
 
    public class gaugeData {
        public String name { get; set; }
        public Integer size { get; set; }
 
        public gaugeData(String name, Integer data) {
            this.name = name;
            this.size = data;
        }
    }
}

 

Hope that helps you move forward.

Best,

Ram

NVaefNVaef

Hey Ram,

 

Thanks for replying so quickly. Sorry for the delay!

 

I'm getting this error: Error: Compile Error: unexpected token: 'controller' at line 5 column 12

 

Edit: I fooled around with it a bit and got it to work - I'll update you with the effects.

 

 

ForcepowerForcepower

ok - good. Sorry - the message got broken up where it should not have.

NVaefNVaef

now i'm having issues putting the inputfield into the visual force.

 

I put the tab within a form in order to use the field, but It is not saving. It's saying that the apex:tab element must have a '>' delimiter, which it does. Also it is saying the issue is on a line with an apex:page element. 

 

I guess what I'm getting at is that I'm not sure how to integrate the VF line you gave me, haha.

 

Edit: Okay, finagled that a bit and got it to work, but now I'm getting Error: Unknown property 'Events__cStandardController.dummyAPJ'

 

ForcepowerForcepower
NV, can you post your VF page?
NVaefNVaef

<apex:form>
<apex:tab label="Gauge Party" rendered="{!Events__c.Meeting_Type__c <> 'Argyle Conversation'}" name="GaugeParty" id="tabGauges">
<apex:pageBlock title="{!$ObjectType.Events__c.label} Gauge">
<apex:pageBlockSection showHeader="true" title="Attendee Goal" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController">
<apex:inputField value="{!dummyAPJ.Attendance_Status__c}" />
<apex:chart name="MyChart" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attendee Goal" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
</apex:page>
</apex:pageBlockSection>
<apex:pageBlockSection showHeader="true" title="Attended" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController2">
<apex:chart name="MyChart2" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attended" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart2.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
</apex:page>
</apex:pageBlockSection>
<apex:pageBlockSection showHeader="true" title="Confirmed" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController3">
<apex:chart name="MyChart3" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Confirmed" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<script>
MyChart3.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>

</apex:page>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:tab>
</apex:form>

ForcepowerForcepower

No need for tabs and cannot have multple pages nested within one page.

 Should be something more like this:

 

// make sure to put the correct value for controller and any other attribs for the  apex:page

<apex:page  ....>
<script>
MyChart.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
<apex:form>

<apex:pageBlock title="{!$ObjectType.Events__c.label} Gauge">
<apex:pageBlockSection showHeader="true" title="Attendee Goal" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController">
<apex:inputField value="{!dummyAPJ.Attendance_Status__c}" />
<apex:chart name="MyChart" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attendee Goal" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
</apex:form>
</apex:page>

NVaefNVaef

Hey Ram,

 

so that worked - I see the gauge displayed with the picklist above it, however no information is being displayed on the gauge. I don't know if the picklist is supposed to auto populate the gauge, or if it needs to be refreshed with a save or button. Nothing happens when I change the value in the picklist essentially. 

 

This is a good idea though, I like the setup. Thank you very much.

NVaefNVaef

Do you think I have to put in a save button to get the data to actually appear on the gauge?

ForcepowerForcepower

Try this:

 

// make sure to put the correct value for controller and any other attribs for the  apex:page

<apex:page  ....>
<script>
MyChart.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>
<apex:form>

<apex:pageBlock title="{!$ObjectType.Events__c.label} Gauge">
<apex:pageBlockSection showHeader="true" title="Attendee Goal" columns="2">
<apex:page standardController="Events__c" extensions="GaugeChartController">
<apex:inputField value="{!dummyAPJ.Attendance_Status__c}" />

         <apex:commandButton action="{!getData}" value="Refresh Chart" / >

<apex:chart name="MyChart" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Attendee Goal" minimum="0" maximum="{!Events__c.Attendee_Number_Goal__c}" steps="5"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
</apex:form>
</apex:page>

                                             

NVaefNVaef

When trying to refresh I get this error:

"Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexListELAdapter"

ForcepowerForcepower

Try changing your signature for getData as line below

public PageReference getData() {

 

 

 

    // replace existing return with this one:

    return null;

}

NVaefNVaef

Well the picklist works now, but the Chart itself is not being displayed.

 

Here's the updated controller:

public class GaugeChartController {
    public String ProjId {get;set;}
    public Attendee_Project_Junction__c dummyAPJ {get;set;} 
    public GaugeChartController(ApexPages.StandardController controller){
        ProjId = controller.getRecord().Id;
        dummyAPJ = new Attendee_Project_Junction__c();
    }
 
    public PageReference getData() {
          Integer TotalAttnds = 0;List<gaugeData> data = new List<gaugeData>();       
         String attendeeStatus = dummyAPJ.Attendance_Status__c;
         AggregateResult[] AttendeeList;
         if (attendeeStatus == 'ALL') {
         AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId                                
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
          }
         else {
         AttendeeList = [select COUNT (Name) numAPJs
                                   from Attendee_Project_Junction__c
                                   where Project__c =: projId                                
                                   and Attendance_Status__c = :attendeeStatus
                                   GROUP BY CALENDAR_MONTH(Event_Date__c) ];
         }                      
if (!attendeeList.isEmpty())
{
    //Do logic with the items in the list
        data.add(new gaugeData('Attendees', Integer.valueOf(attendeeList[0].get('numAPJs'))));   
}
else
        data.add(new gaugeData('Attendees', 0));                              
   

          return null;
}
 
    public class gaugeData {
        public String name { get; set; }
        public Integer size { get; set; }
 
        public gaugeData(String name, Integer data) {
            this.name = name;
            this.size = data;
        }
    }
}

ForcepowerForcepower

try this:

 

public class GaugeChartController {
    public String ProjId {get;set;}
    public Attendee_Project_Junction__c dummyAPJ {get;set;}

    public List<gaugeData> data {get;set;}

 

 

Change your getData to this:

 

public PageReference getData() {
          Integer TotalAttnds = 0;

         data = new List<gaugeData>();       
         String attendeeStatus = dummyAPJ.Attendance_Status__c;
         AggregateResult[] AttendeeList;

 

This was selected as the best answer
NVaefNVaef

That did it! Thank you so much for your help!

 

I know I was a pain this whole time, thank you for your patience!

ForcepowerForcepower
Hey - glad to hear that, Nick! No worries.

Best,
Ram
NVaefNVaef

I'm sorry to do this to you - How do I go about testing that class now?

 

Do I need to reference the refresh button or can I just reference an APJ without a status and then have it update?

ForcepowerForcepower

No worries. You can just assign a value to assignedStatus directly in your test method and then call getData().