Showing posts with label case. Show all posts
Showing posts with label case. Show all posts

Thursday, 8 September 2022

Notify Case Creator when something is posted/commented on Chatter using Salesforce Flow

SCENARIO


While working on one of the requirements for an Electric Automotive Company based in Sweden, there was a requirement to send an Email to the Case creator when something is posted or commented on chatter.

APPROACH


As the requirement is pretty straightforward, The client wants to send an email to the case creator. We have many ways to achieve this requirement like Apex Code, but Salesforce encourages us to code less.

So, we have used Record Trigger Flow to fulfill this requirement.

Below are the steps to achieve the requirement:

Step 1:-  Define flow properties.

  • Click Setup.
  • In the Quick Find box, type Flows.
  • Select Flows then click on the New Flow.
  • Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
    • How do you want to start building: Freeform

Step 2:- Select Object and Set Entry Condition. 

Give Input as follows:
  • Object: Feed Item.
  • Trigger the Flow When: A record is created or updated.
  • Condition Requirements: All Conditions Are Met(AND).
  • Field: ParentId.
  • Operator: Starts With.
  • Value:500(Case Object record Id starts with "500...").
  • When to Run the Flow for Updated Records: Every time a record is updated and meets the condition requirements.
  • Optimize the Flow for Actions and Related Records. 


Step 3:- Get Case Records. 

Drag Get Record Element into canvas from Data Section under Elements Tab from the ToolBox & Give Input as follows:
  • Object: Case.
  • Condition Requirements: All Conditions Are Met(AND).
  • Field: Id.
  • Operator: Equals.
  • Value:{!$Record.Parent:Case.Id}.
  • How Many Records to Store: Only the first record.
  • How to Store Record Data: Automatically store all fields.
  • Join start Element to Get Element.



Step 4:- Create a Decision. 

Drag Decision Element into canvas from Logic Section under Elements Tab from the ToolBox & Give Input as follows:
  • Condition Requirements to Execute Outcome: All Conditions Are Met(AND).
  • Resource: {!Get_Case_Records.CreatedBy.Id}.
  • Operator: Is Null.
  • ValueFalse.
  • When to Execute Outcome: If the condition requirements are met.
  • Join Get Element to Decision Element.

Step 5:- Define Body and Subject Variables for Email.

We need to create flow variables for the Body & Subject portion of the email.
Click New Resource under Elements Tab from the ToolBox & Give Input as follows:
  • Resource Type: Text Template.
  • API Name: TextTemplate.(Write as per your convenience)
  • Body: Comment has been Made. (Write as per your convenience)
  • Click Done.
Repeat the same above steps for Subject.
  • Resource Type: Text Template.
  • API Name: SubjectTemplate.(Write as per your convenience)
  • Body: Hi How are you?. (Write as per your convenience)
  • Click Done.

Step 6:- Send an Email. 

Drag Action Element into canvas from Interaction Section under Elements Tab from the ToolBox, scroll down the list from the left-hand side and select Email from the bottom, in the Action select Send Email & Give Input as follows:
  • Set Body & Subject variables in their respective input field.
  • Press the Don't Include Button for RecipientEmailAddresses(comma-separated) and set it to Include(True).
  • RecipientEmailAddresses(comma-separated):{!Get_Case_Records.CreatedBy.Email}.
  • Click Done.
  • Join Decision Element to Email Action Element for Case Creator.


Step 7:- Now Save the flow & then Activate it.

FLOW DIAGRAM




CONCLUSION


By following the steps mentioned above you can send an Email Notification to Case Creator when something is Posted/Commented on the Chatter.

If you have any questions you can reach out our Salesforce Consulting team here.

Thursday, 7 January 2021

Auto-update case owner of multiple records from list view in Service Console Application

Requirement:

Recently working with Service Console Application, came across a requirement where we need to auto update the Case Owner 
to current logged in user for all the selected case records from the list view. Along with that, we also need to implement it in a such way, so on auto assigning of the records, selected records should be opened in new tabs in a Service Console Application.

Challenge:

Using OOTB features of Salesforce, we can manually update the case owner of only one record at a time. However, in our case, we need to update multiple records with auto assigning of case owner with current logged in user.

Solution:

To achieve this,
  • We need to create a Custom List Button with a content source as a Visualforce page and added it to the Search Layout.
  • Basically, this visualforce page calls an action method from the APEX class and retrieves all the selected records and update case owner of each record based on the current logged in user.
  • We also need to implement JavaScript using Console API to open each updated record in new tab in Service Console Application.
  • The console API versions 42.0 and above of the Salesforce Console Integration Toolkit are supported in the Lightning Console JavaScript API.

ChangeCaseOwnerController Apex Class:

public class ChangeCaseOwnerController { 
    
    ApexPages.StandardSetController setCon; 
    public List<case> listofcases {get; set;} 
    public List<case> returnlist {get; set;} 
    public Map<string,string> returnMap {get; set;} 
   
    public ChangeCaseOwnerController(ApexPages.StandardSetController controller) { 
        setCon = controller; 
        listofcases = (List<case>)controller.getSelected(); //will fetch the selected records from record list
    }

    // method will update the owner of records assigned in listofcases 
    public PageReference changeOwner(){ 
        PageReference pref;
        list<case> caselist = new list<case>();       
 
        for(case c : listofcases){
            c.ownerId = UserInfo.getUserId();
            caselist.add(c);
        } 

        if(caselist.size() > 0){
            try { 
                    update caselist;            
                    returnMap = new Map<string,string>(); 
                    returnlist = [select id,CaseNumber from Case where id IN : lstcase ];  
                    for(Case casechild:  returnlist){ 
                         returnMap.put(casechild.id,casechild.CaseNumber); 
                     }
                  }  
           }
                 catch(DmlException e) { 
                      System.debug('The following Error exception has occurred: ' + e.getMessage());
          } 
       return null; 
    } 
} 

ChangeCaseOwner Visualforce Page:

<apex:page standardController="Case" recordSetVar="cases" extensions="ChangeCaseOwnerController" showHeader="false" action="{!changeOwner}"> 

    <!--include scripts from Salesforce Console Integration Toolkit: --> 
    <script src="../../soap/ajax/48.0/connection.js" type="text/javascript"></script>
    <script src="/support/console/48.0/integration.js" type="text/javascript"></script> 

    <script type="text/javascript">

    var mapofCases = '{!returnMap}'; // assign the map with Case Id and Case Number to variable
    mapofCases=  mapofCases.replace('{',''); 
    mapofCases= mapofCases.replace('}','');
    console.log(mapofCases); 
    var splitArray = mapofCases.split(","); 
 
    openTab(); //calling the function after getting separate case ids

    function openTab(){
        for (var i=0; i < splitArray.length; i++) {            
        openPrimaryTab(splitArray[i]); 
        }
    }

    function openPrimaryTab(arrayid) {
       var caseid=  arrayid.split("=")[0].trim(); 
       var casenumber=  arrayid.split("=")[1].trim();
       sforce.console.openPrimaryTab(undefined,'/'+caseid, true, casenumber);
    }
    </script>
</apex:page> 

Once APEX class and Visualforce page are created, we need to create a Custom List Button. To create a button, 
  • Go to Setup > Object Manager > Case > Buttons, Links, and Actions > New Button  
  • Set Name/Label Select List Button > Content Source Visualforce Page > Content Select Visualforce Page [ChangeCaseOwner]. 

Once all above steps are setup and configured properly, we can see the desired results as shown in below video.
 
Output:


If you have any questions you can reach out to our Salesforce Consulting team here.