function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mario EMario E 

Illegal assignment from Integer to String with Case Thread ID?

I am getting an "Illegal assignment from Integer to String" error on this Apex Class where:

  1. I am trying to retrieve the Case Thread ID (same one that is used in Email-To-Case feature) and this field is a custom text formula data type on the Case record
  2. Change the Case Thread ID font color to light gray (#CCCCCC) in the email body

The errors are pointing to:

String casethreadId.....  (Line 20)

'<span>....  (Line 53)

 

The whole Apex Class:

public class custom_VICasesForwarding {

    @InvocableMethod(Label='forwardToInterpretingDept')
    public static void forwardToInterpretingDept(List<ID> caseRecords){
        Set<Id> createEmailAddresses = new Set<Id>();
        List<Case> caseList = [select Id, 
                                    Subject, 
                                    CaseNumber, 
                                    Case_Reason__c, 
                                    Case_Issue__c, 
                                    Description, 
                                    Date_Time_of_Call__c, 
                                    VINumber__c, 
                                    Customer_s_VP__c, 
                                    Outbound_Audio__c,
                                    Case_Thread_ID__c,
                              (select Id from EmailMessages)
                              from Case where Id IN :caseRecords];

        String casethreadId = String.valueOf(Case.Case_Thread_ID__c);

        for(Case c: caseList){
            // Pulls field data from Case to include in the email body
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            String[] toaddr = new String[System.Label.custom_VIEmailAddresses.split(',')];
            string[] ccaddr = new string[]{};
            email.setSubject('FW: ' + c.CaseNumber + ' : ' + c.Case_Reason__c);
            email.setHtmlBody('Case Number: ' + c.CaseNumber
                                + '<br/>' + 
                                'Case Reason: ' + c.Case_Reason__c 
                                + '<br/>' +
                                'Case Issue: ' + c.Case_Issue__c 
                                + '<br/>' + 
                                + '<br/>' +
                                'Date/Time: ' + c.Date_Time_of_Call__c 
                                + '<br/>' + 
                                'VI #: ' + c.VINumber__c
                                + '<br/>' +
                                'Customer\'s VP #: ' + c.Customer_s_VP__c
                                + '<br/>' +
                                'Outbound Audio #: ' + c.Outbound_Audio__c
                                + '<br/>' +
                                + '<br/>' +
                                + '<br/>' +
                                'Case Description: ' + c.Description 
                                + '<br/>' +
                                + '<br/>' +
                                + '<br/>' +
                                '<i>' + '*Note: If there are any null values, this means this information was not provided by the Case Owner prior to this submission.' + '<i>'
                                + '<br/>' +
                                '<span style="color: #cccccc;">' + casethreadId + '</span>');
            email.setToAddresses(toaddr); 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();   
        
    }  
}
Best Answer chosen by Mario E
Shubham_KumarShubham_Kumar
Hi Mario
I don`t think line 20 will produce this error because the value being assigned is a string value so it will just give you
casethreadId = 'Case_Thread_ID__c';
if i am not wrong you want to use the value of Case_Thread_ID__c for each record then you will have to put it inside the loop and assign the value.
String casethreadId = String.valueOf(c.Case_Thread_ID__c);
Also can you post the full errror here so that we could understand it better.