You need to sign in to do that
Don't have an account?
Radar chart with Apex - Invalid ID problem
Hi all,
I am attempting to build a radar chart based off of this (https://github.com/developerforce/Visualforce-Charting-Examples" rel="nofollow) github page :
I've created the Account field set and included my three test variables in the field set. I've barely touched the base code yet, but I'm getting an error message when trying to preview the page. "System.QueryException: invalid ID field: null. Class.XXX.RadarChartController.getData: line 28, column 1"
Apex page code:
<apex:page standardController="Account" extensions="RadarChartController"> <style> #vfext4-ext-gen1026 { width:800px !important; } </style> <apex:chart name="myChart" height="600" width="650" legend="false" data="{!data}"> <apex:legend position="left" /> <apex:axis type="Radial" position="radial"/> <apex:radarSeries title="Customer Satisfaction" xField="field" yField="value" tips="true" opacity="0.4"/> </apex:chart> </apex:page
Apex class code
public class RadarChartController { public List<Map<Object,Object>> data = new List<Map<Object,Object>>(); public String acctId {get;set;} public RadarChartController(ApexPages.StandardController controller){ acctId = controller.getRecord().Id; //'001x00000035SrC'; } public List<Schema.FieldSetMember> getFields() { return SObjectType.Account.FieldSets.RadarSet.getFields(); } public List<Map<Object,Object>> getData() { String query = 'SELECT '; List<String> fieldNames = new List<String>(); for(Schema.FieldSetMember f : getFields()){ query += f.getFieldPath() + ', '; fieldNames.add(f.getFieldPath()); } query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1'; SObject myFieldResults = Database.Query(query); Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe(); Map<String, Schema.SObjectField> fieldMap = R.fields.getmap(); //creates a map of labels and api names Map<String,String> labelNameMap = new Map<String,String>(); for(String key : fieldMap.keySet()){ labelNameMap.put(fieldMap.get(key).getDescribe().getName(), fieldMap.get(key).getDescribe().getlabel()); } //creates a map of labels and values for(String f : fieldNames){ String fieldLabel = labelNameMap.get(f); String fieldValue = String.valueOf(myFieldResults.get(f)); Map<Object, Object> m = new Map<Object,Object>(); m.put('field', fieldLabel); m.put('value', fieldValue); data.add(m); } return data; } }
Never done much in Apex before, and this has me stuck. I changed line 25 in the controller code to make the query look for a specific account ID, but that didn't fix the problem. Any ideas?
Thanks!
for this to work, you need to pass an existing account id in your salesforce org to the page..
if your page name is radarchart, then your url should look like this
/apex/radarchart?id=001x00000035SrC
replace 001x00000035SrC with an existing id in your salesforce org which has values in the fields you are querying and displaying in the chart..
All Answers
for this to work, you need to pass an existing account id in your salesforce org to the page..
if your page name is radarchart, then your url should look like this
/apex/radarchart?id=001x00000035SrC
replace 001x00000035SrC with an existing id in your salesforce org which has values in the fields you are querying and displaying in the chart..
Yes, I was trying to preview the VisualForce Page, which didn't have any account ID associated thus giving me the error. Your comment helped me understand. Thanks very much.
John