Showing posts with label ListView. Show all posts
Showing posts with label ListView. Show all posts

Thursday, 27 July 2023

Enhancing Record Processing: Automating Bulk Operation with Salesforce Flow from List Views

Requirement:

In an E-commerce sector project, the client based in Georgia, USA was required to implement bulk operation(To update multiple records simultaneously) from a list view button using salesforce flow.

Challenge:

As we do not have to use the apex class for this requirement, our main challenge was passing all the selected record Ids from the sObject's list view to the salesforce flow.

Solution:


Concisely, To achieve this follow the below steps:
  • Creating a screen flow with a variable named "ids" for delete operation.
  • Creating a List button with a custom URL.

 

  • To Create Screen Flow:
  • Go to the setupQuick Find search box ⇒ Flows.  
  • After that click on New Flow and then select Screen Flow.
  • To create a collection variable go to the toolbox and click on New Resource button.
  • Select Variable as Record Type and Enter values as in below image.

 

  

[Note: API Name of the variable must be "ids".] 

  •  After that create a variable for record count to assign the count of the ids. 

 

 

  •  Add Decision Element and enter values as below.

 


  •  Add Delete Record element for Available outcome and add Screen element for Not Available outcome to display Error message. 

 

 

  • After Delete Record element add Screen element for success message.
  • Have a look on below image for flow reference.

 

 

  • To create a List Button with a custom URL:
  • Go to the Object Manager and open sObject(here it is Account) then click on "Buttons, Links and Actions" Tab.
  • Then click on "Create Button or Link" button and enter values as below in image and click on save button.

 

 

  • Here the custom URL "/flow/Delete_bulk_records?retURL=001/o" includes API Name of flow i.e. Delete_bulk_records and retURL=001/o to return to the Accounts List View page.
  • The value of retURL 001/o includes "001" is from first three character of record Id of Account sObject and "o" to redirect to the list view page.
  • After creating List Button click on List View Button Layout to add the List Button in List View Layout.
  • Edit the List view Layout, Scrolldown the cursor to the Custom Button and Add the created List Button in the Selected button list and save the changes. 

 

Output: 

 


Conclusion:

This is how the Automating Bulk Operation with Salesforce Flow from List Views is implemented which allows you to update multiple records simultaneously, saving time and effort.

  

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.