+ Start a Discussion
Justin DJustin D 

Compile Error: Illegal assignment from List <...> to String

Hi Everyone,
I am trying to find how to go about resolving this error. I am new to Apex.
   Compile Error: Illegal assignment from List<SurveySelection__c> to String at line 23 column 13

Bottom is my code:
By the way, the data type for "SurveySelection__c" is Number(2,0). I am not sure whether that matters. 
-----------------------------------------------------------------------------------------------------------------------------------------------------
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;  // This is line where error occurs
            
            RowList.add(tr);
        }
    }
}


-----------------------------------------------------------------------------------------------------------------------
Thanks in advance!

Amit Chaudhary 8Amit Chaudhary 8
You are assigning List of SurveySelections__r into String ( SurveySelection ). So please convert the SurveySelection  into List.

Try to update your code like below
public class WrapperDemoController
{
    public class TableRow{
        public String sfsid {get;set;}
        public String SurveySelection   {get;set;}
        public List<SurveySelections__c> lstSurveySelection {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;  // This is line where error occurs
            tr.lstSurveySelection = con.SurveySelections__r; 
            RowList.add(tr);
        }
    }
}

 
GauravGargGauravGarg
Hi Justin,

Please replace line 23 with below line:
tr.SurveySelection = con.SurveySelections__r.surveySelection__c;

Hope this helps, let me know if you still face the issue.

Thanks,
Gaurav​
Justin DJustin D
Hi Amit,
Thanks for your help. Greatly appreciated.
I tried the code you provided me. I am getting "Invalid type: SurveySelections__c at line 6.."
Amit Chaudhary 8Amit Chaudhary 8
Hi Justin,

Can you please check the API name of SurveySelection object. May be same will be SurveySelection__c
Please replace SurveySelections__c with object API name

And let us know if this will help you
 
Matheus AbudMatheus Abud
Hey guys, I think I'm going through something familiar, but I can't seem to figure it out..
What I need to do is: I have a custom object (choices__c) where I'm building a VFP within it. In this VFP I have to query data from another custom object (products__c). I just can't query the data. After that I'll still have to put it in a dropdown list in order for the client to choose the products and start adding it to order.
Can you guys give me some hints?

See below my VF page:
<apex:page controller="Choice">
    <apex:form >
        <span>Choices: </span>
        <apex:selectList size="1">
            <apex:selectOptions value="{! allChoices}" />   
        </apex:selectList>
    </apex:form>
</apex:page>
See below my choice controller:
So, my list is working fine. When I changed it for the 2 lines in line 5 and 6 in order to query the data in put in the list, I can't get done.
public with sharing class Choice 
{
    //public String querychoices {get; set;}	    
    public Choice() 
    {
//      String querychoices = [SELECT name FROM product__c];
//      List<product__c> choices = Database.query(querychoices);
//      So, my list is working fine. When I changed it for the 2 lines above in order to query the data in put in //      the list, I can't get done.
        List<String> choices = new List<String>();
		for (integer i=0; i<5; i++)
        {
            choices.add('apple_'+i);
        }
        this.allChoices = new SelectOption[]{};
        
        for (String c: choices) 
        {
            this.allChoices.add(new SelectOption(c,c));
        }
    }

    public SelectOption[] allChoices 
    {
        public get;
        private set;
    }
}