I have a Apex Class with following code.

global class MyClass{
    global string myMethod(){
        String[] lablesArray = new String[]{'Expensive','Call','Room','Raliabity','Performance','Nurses','Security','Care','Doctors','Emergency','Recovery'};
        Integer[] vals = new Integer[]{277,221,109,125,120,73,76,61,112,156,72};
        list<DataSet> data = new list<DataSet>();
        for(Integer i = 0; i< lablesArray.length; i++){
            DataSet d = new DataSet();
            d.lable = lablesArray[i];
            d.val = vals[i];
        return JSON.serialize(data);

    virtual class DataSet{
        String lable;
        Integer val;

when I try to save it I am getting following error

Initial term of field expression must be a concrete SObject: List


length is not a property of list in salesforce, use size() method.


for(Integer i = 0; i < lablesArray.length; i++){


for(Integer i = 0; i < lablesArray.size(); i++){

Always try to understand the error message, and documentation are best place to look for it. Please refer List Methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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