I am trying to find how to go about resolving this error.

Compile Error: Illegal assignment from List to String at line 23 column 13

By the way, the data type for "SurveySelection__c" is Number(2,0).

I am not sure whether that matters.

Bottom is my code:

public class WrapperDemoController{

public class TableRow{
    public String sfsid {get;set;}
    public String SurveySelection   {get;set;}

public List<TableRow> RowList {get; set;}

public WrapperDemoController(){

    RowList = new List<TableRow>();
    TableRow tr;

    for(Student__c con : [SELECT sfsid__c, (select SurveySelection__c from SurveySelections__r) FROM Student__c]){

        tr = new TableRow();
        tr.sfsid = con.sfsid__c;
        tr.SurveySelection = con.SurveySelections__r;  // Line 23: This is line where error occurs**

  • You are facing this issue because, SurveySelection has a String data type and you are trying assign a SurveySelections__r which is of type list.
    – Devendra
    May 17, 2017 at 22:26
  • I am trying to get the value from related table - SurveySelection__c. Where do I have to modify? Should I change the SOQL statement? I was trying to mimic this example (Wrapper) success.salesforce.com/answers?id=90630000000hSoLAAU
    – Java
    May 17, 2017 at 22:30

1 Answer 1


If you just want the string value then you can do this:

tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;

If you have multiple rows you will need to figure out which one you want to get. Since the query on the related records is a List of the related records you cannot just assign the list to a string.

You must log in to answer this question.

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