Home > trigger > Trying to assign a string result from a query into a trigger's string variable

Trying to assign a string result from a query into a trigger's string variable

January 8Hits:0
Advertisement

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

Answers

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:

Tags:trigger, soql

Related Articles

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.810 s.