1

I'm trying to assign a string result from a query into a trigger's string variable, and this is the error I receive:

Compile Error: Illegal assignment from LIST to String at line 42 column 12

string SEMCODE;

// Most Recent SEM Code
SEMCODE = [select SEM_Code__c from Interaction__c where Contact__c = :record.Contact__c
           ORDER BY Start_Date_Time__c Desc Limit 1];

How can I get the SEM_Code__c value from the single record query result?

Thanks,

Kevin

1 Answer 1

6

The reason for the error message was that you were assigning a List into string variable, which the system will not allow. You can do something like this:

 string SEMCODE;
 SEMCODE = [SELECT SEM_Code_c 
            FROM Interaction_c 
            WHERE Contact_c = :record.Contact_c 
            ORDER BY Start_Date_Time__c DESC LIMIT 1].SEM_Code__c;

You can find more information about this here:

3
  • 1
    Thanks theGreatDanton, it compiled, now to finish this thing! Commented Jan 8, 2014 at 15:26
  • @KevinRussell Do you also understand why this works and what you were doing wrong ? Commented Jan 8, 2014 at 15:44
  • Not exactly, but I imagine the query is a query object and the .SEM_Code__C is how to access the field property.... It did work for me in my trigger. Commented Jan 8, 2014 at 19:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.