• Mario E
  • NEWBIE
  • 20 Points
  • Member since 2019
  • SFDC Guy

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 10
    Replies

I am using LEX and I want to have an Apex Class to include all the Salesforce Files that the Case has as attachments to the email and send the email.

I have a currently working Apex Class that sends the email just fine. I just need to add the attachment code and I am not sure where to start - I tried to use ContentDocumentLink but I have no clue of how to write that code. I doubt EmailFileAttachment works because I am using LEX which Salesforce Files work a bit differently.

 

Here is the current code:

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

        for(Case c: caseList){
            // Get Org Wide Email Address and then set it as Reply To address
            OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'younameit@emailcompany.com'];
            // Define the email
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            if ( owea.size() > 0 ) {
                email.setOrgWideEmailAddressId(owea.get(0).Id);
            }

            // Sets the TO addresses
            String[] toaddr = new String[System.Label.custom_VIEmailAddresses.split(',')];
            string[] ccaddr = new string[]{};

            // Pulls field data from Case to include in the email body
            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/>' +
                                + '<br/>' +
                                + '<br/>' +
                                '<span style="color: #cccccc;">' + c.Case_Thread_ID__c + '</span>'
                                + '<br/>' +
                                + '<br/>');

            email.setToAddresses(toaddr);

            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();   
    }  
}

When a Case is closed, it will trigger an Apex class to send an email with the Case details. However, when someone replies to the email, it will go to the Case Owner's work Gmail instead of back to the same Case using the Email-To-Case feature that is already set up and working properly.
I even included the Case Thread Id in the Apex Class and I see it in the email body being sent. 

 

How can I make sure the replied email arrives back in the Case that triggers the Apex Class?

I created a VFP and Apex Controller that will run a Flow. In the flow, the Case ID will be passed through and take the user back to the same Case record after clicking a custom button.

The only issue here is that the page does not refresh to display the changes after the flow was executed.

// Redirects user to the same Case record after flow executes and reloads the page

public with sharing class custom_caseJiraFlowRedirectController {
    public Object custom_caseJiraFlowRedirectController() {
            String unique_id = ApexPages.currentPage().getParameters().get('id');
            if(unique_id == null){
               // Return Home if no ID 
               String url = '/home/home.jsp';
               return new PageReference(url); 
        } // Get Case ID and set Redirect
          String caseId = [SELECT Id,
                              caseFlowUniqueId__c
                              FROM Case
                              WHERE caseFlowUniqueId__c = :unique_id
                              ORDER BY CreatedDate
                              DESC LIMIT 1].Id;
           // Did we find a Case?
           if (caseId == null) {
           // Return Home if no ID
           String url = '/home/home.jsp';
           return new PageReference(url);
           }
           // Redirect to Case
           String url = '/' + caseId;
          return new PageReference(url); 
      }
  }

Do I need to add this line somewhere?
System.PageReference setRedirect(Boolean redirect)

User-added imageWhen the FINISH button at the end of the flow is clicked, it leads back to the record but does not refresh the page to bring in the changes pushed through the flow that was executed.

 

How to have the page refresh automatically?

I have data from external data warehouse pushing data through Skyvia to Salesforce. It will upsert Contacts. However, I want to know how to have the process check if there is any existing lead with same email then convert that lead to a Contact then update that same Contact. 

Right now, our salespeople have to keep manually check if the Contact got created in Salesforce then they will need to go to the lead and manually convert and then choose the matching Contact. This needs to (and I know it can be) automated!

 

How can I achieve that? 

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();   
        
    }  
}

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();   
        
    }  
}

​​​​​​​

I am using LEX and I want to have an Apex Class to include all the Salesforce Files that the Case has as attachments to the email and send the email.

I have a currently working Apex Class that sends the email just fine. I just need to add the attachment code and I am not sure where to start - I tried to use ContentDocumentLink but I have no clue of how to write that code. I doubt EmailFileAttachment works because I am using LEX which Salesforce Files work a bit differently.

 

Here is the current code:

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

        for(Case c: caseList){
            // Get Org Wide Email Address and then set it as Reply To address
            OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'younameit@emailcompany.com'];
            // Define the email
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            if ( owea.size() > 0 ) {
                email.setOrgWideEmailAddressId(owea.get(0).Id);
            }

            // Sets the TO addresses
            String[] toaddr = new String[System.Label.custom_VIEmailAddresses.split(',')];
            string[] ccaddr = new string[]{};

            // Pulls field data from Case to include in the email body
            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/>' +
                                + '<br/>' +
                                + '<br/>' +
                                '<span style="color: #cccccc;">' + c.Case_Thread_ID__c + '</span>'
                                + '<br/>' +
                                + '<br/>');

            email.setToAddresses(toaddr);

            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();   
    }  
}

When a Case is closed, it will trigger an Apex class to send an email with the Case details. However, when someone replies to the email, it will go to the Case Owner's work Gmail instead of back to the same Case using the Email-To-Case feature that is already set up and working properly.
I even included the Case Thread Id in the Apex Class and I see it in the email body being sent. 

 

How can I make sure the replied email arrives back in the Case that triggers the Apex Class?

Newbie Question: I am trying to write an IF statement in a report using a number field. IF( NUM Field = 4, IF TRUE, Or FALSE). For some reason I can not get the logical statement to work. The field i am using is Quarter__c but it says that the field does not exist. Any help is recommended. Thank you :)

I have data from external data warehouse pushing data through Skyvia to Salesforce. It will upsert Contacts. However, I want to know how to have the process check if there is any existing lead with same email then convert that lead to a Contact then update that same Contact. 

Right now, our salespeople have to keep manually check if the Contact got created in Salesforce then they will need to go to the lead and manually convert and then choose the matching Contact. This needs to (and I know it can be) automated!

 

How can I achieve that? 

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();   
        
    }  
}

​​​​​​​
I am a system administrator for my org and I am using the Trail Tracker to assign custom trailmixes to our employees. I was using the trailmix assignment functionality without issues but something changed and now it works only sporadically. 

I thought this was a permission issue, and that someone in my org edited the permissions, but I followed the guide here and there doesn't seem to be permission issues. https://quip.com/AVc8Aouc4Lzx 

When I make an assignment, the app says that the assignment is in progress, check the debug logs for success, but when I check the debug logs, it doesn't show any signs of trouble working with the Trailhead API. 

Has anyone came across this or a similar problem in the past? Also, if I uninstall and reinstall the Trail Tracker App, will I be able to retain my current Trailmix and user badge assignments? 

Thanks