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 

Inserting another public static void in an Apex Class?

How can I insert this public static void in my existing Apex Class and include the Case Thread Id in the email?

To insert:

public static String ThreadId(String caseid)
    {

        string Case_ThreadID = '_' + UserInfo.getOrganizationId().left(4) + '0' ;
        Case_ThreadID = Case_ThreadID + UserInfo.getOrganizationId().mid(11,4) + '._';
        Case_ThreadID = Case_ThreadID + caseid.left(4) + '0' + caseId.mid(10,5);

        return Case_ThreadID;
    }


My existing Apex Class:

// Sends Case information to the Interpreting Department
// Email addresses are listed under Custom Labels: custom_VIEmailAddresses

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,
                              (select Id from EmailMessages)
                              from Case where Id IN :caseRecords];

        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/>');
            email.setToAddresses(toaddr); 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();   
        
    }  
}

​​​​​​​
Best Answer chosen by Mario E
Marc D BehrMarc D Behr
The formula would look something like: 
"ref:_" & LEFT($Organization.Id,5) & SUBSTITUTE(RIGHT(Organization.Id,11), "0", "" )& "._" & LEFT(Id,5) & SUBSTITUTE(Left(RIGHT(Id,10), 5), "0", "") & RIGHT(Id,5) & ":ref"

 

All Answers

Marc D BehrMarc D Behr
Why not just make the threadID a formula field in the case object so it is available for other purposes as well? 
Mario EMario E

Good idea! Did not think of that. How do I get that as a custom field? Formula field and just put in the formula:

string Case_ThreadID = '_' + 
UserInfo.getOrganizationId().left(4) + 
'0' ;Case_ThreadID = Case_ThreadID + 
UserInfo.getOrganizationId().mid(11,4) + 
'._';
Marc D BehrMarc D Behr
The formula would look something like: 
"ref:_" & LEFT($Organization.Id,5) & SUBSTITUTE(RIGHT(Organization.Id,11), "0", "" )& "._" & LEFT(Id,5) & SUBSTITUTE(Left(RIGHT(Id,10), 5), "0", "") & RIGHT(Id,5) & ":ref"

 
This was selected as the best answer
Mario EMario E
That worked well! With one modification to include the $ before Organization after ...SUBSTITUTE(RIGHT(Organization...:
 
"ref:_" & LEFT($Organization.Id,5) & SUBSTITUTE(RIGHT($Organization.Id,11), "0", "" )& "._" & LEFT(Id,5) & SUBSTITUTE(Left(RIGHT(Id,10), 5), "0", "") & RIGHT(Id,5) & ":ref"