Loading
Salesforce now sends email only from verified domains. Read More
Agentforce Contact Center
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create a Case When a Messaging Session Starts Outside of Your Business Hours

          Create a Case When a Messaging Session Starts Outside of Your Business Hours

          Let end users submit a case when trying to message outside of business hours. Use an Apex class and a bot to run a business hours check, then create the case from a flow.

          Required Editions

          View supported editions.
          Checkmark This article applies to: Enhanced In-App Chat and Enhanced Web Chat channels
          X icon This article doesn’t apply to: Enhanced WhatsApp, Standard and Enhanced Facebook Messenger, Standard and Enhanced SMS, Enhanced Apple Messages for Business, Enhanced LINE, and Bring Your Own Channel
          User Permissions Needed
          To create business hours: Manage Business Hours Holidays
          To add business hours to your deployment: Customize Application AND Modify Metadata Through Metadata API Functions

          Create an Apex Class

          Create a public Apex class that checks if an end user is attempting to message outside of your business hours.

          Add this code snippet to your Apex class.
          public class CheckWithinBusinessHours {
          
           @InvocableMethod(label = 'Check Within Business Hours')
           public static List<Boolean> makeGetCallout(List<String> Name) {
          
          String BHName= String.valueOf(+Name[0]);
          
          // Get Business hours based on name, input from bot
          BusinessHours bh = [SELECT Id FROM BusinessHours WHERE name= :BHName];
          
          // Create Datetime with current date/time in local time zone
          Datetime targetTime = Datetime.now();
          
          // Find whether the time is within business hours
          Boolean isWithin= BusinessHours.isWithin(bh.id, targetTime);
          
           return new List<Boolean>{isWithin};
          
           }}

          Create Business Hours

          Create a business hours record for your Apex class to reference.

          Create a set of business hours. For the purposes of this recipe, don’t associate a business hours record with your Enhanced Chat deployment.

          Create a Flow

          Create an Auto-Launched flow that creates a case when a customer messages outside of business hours.

          1. Create a new flow. Select Autolaunched Flow (No Trigger)as the flow type.
          2. Create a new flow Resource:
            1. In the Resource Type field, select Variable.
            2. In the API Name field, enter CaseNumber.
            3. In the Data Type field, select Text.
            4. In the Data Type field, select Text.
            5. Click Done.
          3. Create a second flow Resource:
            1. In the Resource Type field, select Variable.
            2. In the API Name field, enter Subject.
            3. In the Data Type field, select Text.
            4. Select Available for input.
            5. Click Done.
          4. A CaseId from Create_Case variable is generated automatically when the Create Records element is added to your flow.To create a Case record and return the Case Number to the user in the bot, add a Create Records element.
            1. In the How to Set the Record Fields dropdown, select Manually.
            2. In the Object dropdown, select Case.
            3. Under Set Field Values for the Case, select Subject in the Field dropdown and enter Einstein Bot Case in the Value dropdown.
            4. Click Done.
          5. Save and activate your flow.

          Add the Apex Class to Your Bot

          Update your bot by adding the Apex class. While this Apex action could be placed and executed anywhere in your bot, this example invokes the class in the Transfer to Agent dialogue.

          1. Add an Apex action component to the Transfer to Agent dialogue for your bot. This component lets you associate the Apex class that you created in step 1 to your bot.
            1. In the Action Type field, select Apex.
            2. In the Action Name field, select the apex class you created in step 1.
            3. Verify that the Input field displays Name (string).
            4. In the Source field, select Value.
            5. In the Custom Value, enter the name of your business hours record.
            6. Verify that the Output field displays Output (Boolean).
            7. Click inside the Variable Name field, and select +New Boolean Variable.
            8. In the Type field, select Custom.
            9. In the Name field, enter IsWithinBusinessHours. To give it the same API name, click inside the API Name field.
            10. Verify that the Data Type field displays Boolean.
            11. Save your changes.
            12. Save your changes in the Bot Builder.
          2. Add a dialogue that creates a case if the Apex class returns false when checking to see if the messaging session is initiated outside of business hours.
            1. Click the + icon to the right of the search field in the Bot Builder, and select New Dialogue.
            2. Name your dialog, give it a description, and optionally, assign it to a dialog group.
            3. Add a Flow component to the dialogue.
            4. Verify that the Action Type field displays Flow.
            5. In the Action Name field, select the flow that you created previously.
            6. Verify that the Input field displays Subject (string).
            7. In the Source field, select Value.
            8. In the Custom Value field, enter Einstein Bots Case.
            9. Verify that the Output field displays CaseNumber (string).
            10. In the corresponding Variable Name field, select + New Text Variable.
            11. In the Type field, select Custom.
            12. In the Name field, enter Case Number. To give the text variable a similar API name, click inside the API field.
            13. Verify that the Data Type field displays Text.
            14. Save your changes.
            15. Save your changes to the Bot Builder.
          3. Return to the Transfer to Agent dialogue and add a Redirect to Dialogue component. This component redirects to the Create a Case dialogue when an end user tries to chat outside of business hours.
            1. Click +Add Condition.
            2. In the Variable Name field, select IsWithinBusinessHours (boolean).
            3. In the Operator field, select Is False.
            4. In the Rule Action field, select Redirect to Dialogue.
            5. In the Redirect Type field, select Dialogue.
            6. In the Dialogue Case field, select the dialogue that you created in step 4b.
          4. Save your changes in the bot builder.
          5. Activate your bot.
           
          Loading
          Salesforce Help | Article