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
TechEd_ProgrammerTechEd_Programmer 

Service Console Custom Component - VF Page

Ok.....just need a bit of help to understand what I am doing wrong.

 

I have all of the attributes I need to display this page in the left subtab sidebar of the service cloud console....I think. I am not sure why it is not showing anything. I have records that should be aggregating and they are not. Can someone tell me why?

 

Controller:

public class NS_ConsoleCaseChartController {
	
	public String strContactID;
	public String strCaseID;
	
	public NS_ConsoleCaseChartController(ApexPages.StandardController stdController){
        strCaseID = ApexPages.currentPage().getParameters().get('Id');
	}
	
	public List<ChartDataItem> getChartData()
	{
		List<ChartDataItem> items = new List<ChartDataItem>();
		
		strContactId = string.valueOf(Case.ContactId);
		
		AggregateResult[] groupedTasks = [SELECT Type, Count(Id) ID FROM Task WHERE WhoId =: strContactID GROUP BY Type];
		
		for (AggregateResult ar : groupedTasks)
		{
			items.add(new ChartDataItem( String.valueOf(ar.get('Type')), Integer.valueOf(ar.get('ID'))));
		}
		
		System.debug(items);
		return items;
	}
	
	public class ChartDataItem
	{
		public String Label {get; set;}
		public Integer Value {get; set;}
		
		public ChartDataItem(String Label, Integer Value)
		{	
			this.Label = Label;
			this.Value = Value;
		}
	}
}

 VF Page:

<apex:page standardController="Case" extensions="NS_ConsoleCaseChartController">
<apex:includeScript value="/soap/ajax/26.0/connection.js"/>
<apex:includeScript value="/support/console/26.0/integration.js"/>
<script type="text/javascript">  
  function openNewSubtab() {
      sforce.console.getFocusedPrimaryTabId(Id);
  	} 
</script>  
	<apex:chart height="195" width="250" data="{!chartData}">
        <apex:pieSeries dataField="Value" labelField="Label"/>
        <apex:legend position="bottom"/>
    </apex:chart>
</apex:page>

 I am really trying to figure out what I am missing here. I am new to developing in the Service Cloud Console.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jayjaysjayjays

Hi,

 

none of the Label values can be null or the pie chart will not render, try adding this to you controller;

 

if (ar.get('Type')==null){
items.add(new ChartDataItem( String.valueOf('Other'), Integer.valueOf(ar.get('ID'))));}
else{
items.add(new ChartDataItem( String.valueOf(ar.get('Type')), Integer.valueOf(ar.get('ID'))));}

 

Cheers.

All Answers

jayjaysjayjays

Hi,

 

custom console components that sit in the sidebar can just be a visualforce page using the standard controller, no need to reference the service console API unless you wish to interact with the console.

 

Also, when using a controller extension you cannot reference the object in your controller code like you have 'Case.ContactId', you need to get the record in the extension constructor using stdController.getRecord().  You must also have a reference in the vf to the fields you wish to use in the controller logic, this can be hidden on the page.

 

Thanks,

J

 

The vf and extension would look something like this;

 

VF Page:

 

<apex:page standardController="Case" extensions="NS_ConsoleCaseChartController">
<apex:outputText rendered="false" value="{!Case.contactId}"/> <apex:chart height="195" width="250" data="{!chartData}"> <apex:pieSeries dataField="Value" labelField="Label"/> <apex:legend position="bottom"/> </apex:chart> </apex:page>

Controller extension

 

public class NS_ConsoleCaseChartController {
	
	private final Case c;
	
	public NS_ConsoleCaseChartController(ApexPages.StandardController stdController){
        c=(Case)stdController.getRecord();
	}
	
	public List<ChartDataItem> getChartData()
	{
		List<ChartDataItem> items = new List<ChartDataItem>();
		
		strContactId = string.valueOf(c.ContactId);
		
		AggregateResult[] groupedTasks = [SELECT Type, Count(Id) ID FROM Task WHERE WhoId =: strContactID GROUP BY Type];
		
		for (AggregateResult ar : groupedTasks)
		{
			items.add(new ChartDataItem( String.valueOf(ar.get('Type')), Integer.valueOf(ar.get('ID'))));
		}
		
		System.debug(items);
		return items;
	}
	
	public class ChartDataItem
	{
		public String Label {get; set;}
		public Integer Value {get; set;}
		
		public ChartDataItem(String Label, Integer Value)
		{	
			this.Label = Label;
			this.Value = Value;
		}
	}
}
TechEd_ProgrammerTechEd_Programmer

Good News is that the debugger shows that my aggregations are working, however the VF page is still not displaying a pic chart in the Service Cloud Console. Any odeas?

jayjaysjayjays

Hi,

 

none of the Label values can be null or the pie chart will not render, try adding this to you controller;

 

if (ar.get('Type')==null){
items.add(new ChartDataItem( String.valueOf('Other'), Integer.valueOf(ar.get('ID'))));}
else{
items.add(new ChartDataItem( String.valueOf(ar.get('Type')), Integer.valueOf(ar.get('ID'))));}

 

Cheers.

This was selected as the best answer
TechEd_ProgrammerTechEd_Programmer

Thank you very much. that gave me what I needed.