0

Attempting to build a radar chart based off of this github page :

I've created the Account field set and included my three test variables. 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!

1 Answer 1

1

The exception you report is consistent with the accId being null.

When you write a (view) controller that extends a standard controller, you must supply an existing object ID of the right type when you open the page:

/apex/RadarDemo?id=001x00000035SrC

This is used by the standard controller to query any fields referenced in the page and is also made available to your controller extension.

(You can find such an ID by just viewing an Account and taking the ID from the URL.)

If you are still suck, you can output information to the debug log to narrow down the problem as descried in How do I start to debug my own Apex code?.

You must log in to answer this question.

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