+ Start a Discussion
John SamuelsJohn Samuels 

Invalid assignment error in APEX graph

 Hi,

I am trying to create this graph in APEX. I am getting an error "Illegal assignment from LIST<Account> to LIST<XXX.Sample.RadarWedgeData>". Is this most likely because of a integer vs. number data type problem, a lack of data, or something else? Thanks
 

public class Sample {
    List<String> xx = new List<String> {'Planning','Management','Tax','Risk','Liability'};
    
    public class RadarWedgeData {
public Integer data1 { get; set; }
public Integer data2 { get; set; }
public Integer data3 { get; set; }


public RadarWedgeData(Integer data1 , Integer data2,Integer data3) {
this.data1 = data1;
this.data2 = data2;
this.data3 = data3;
}
}
    
    public List<RadarWedgeData> getData(){
          List<RadarWedgeData> memList = new List<RadarWedgeData>();
           memList = [SELECT test1__c, test2__c, test3__c from Account where ID = '001F0000018glHz'];
           for (Account mem: memList){              
               data.add(new RadarWedgeData(mem.test1__c, mem.test2__c, mem.test3__C));
        }
}
}


Best Answer chosen by John Samuels
Vamsi KrishnaVamsi Krishna
John,
you are querying Accounts using SOQL in your getData method and assigning the returned List of Accounts to a List of RadarWedgeData type which is throwing the error..

if you change the code to below, it should work

public class Sample {

  List<String> xx = new List<String> {'Planning','Management','Tax','Risk','Liability'};
    
  public class RadarWedgeData {
    public Integer data1 { get; set; }
    public Integer data2 { get; set; }
    public Integer data3 { get; set; }

    public RadarWedgeData(Integer data1 , Integer data2,Integer data3) {
      this.data1 = data1;
      this.data2 = data2;
      this.data3 = data3;
    }

  }
    
  public List<RadarWedgeData> getData(){
     List<RadarWedgeData> memList = new List<RadarWedgeData>();
     Account acc = [SELECT test1__c, test2__c, test3__c from Account where ID = '001F0000018glHz'];                  
     memList.add(new RadarWedgeData(acc.test1__c, acc.test2__c, acc.test3__C));
     return memList;
  }

}