Skip to content
Salesforce

Enhance the standard Change Owner functionality

•11 min read•4 reads
Enhance the standard Change Owner functionality

Business Requirement 

Change owner is a standard functionality in Salesforce, which brings a flyout as shown below.

This functionality doesn’t allow us to change a reason (or any other fields) while changing the owner for a record.

In order to overcome this limitation, we can create a custom action button to change the owner for the record and  make the user enter a reason for the owner change on Screen Flow.

STEPS TO ACHIEVE THE REQUIREMENT :

  1. Create two Custom Fields (lookup and formula fields)
  2. Create Custom Notification (for in-app notification)
  3. Create an Email Template
  4. Create an Email Alert
  5. Create Screen Flow
  6. Create Custom action button

Create two Custom Fields

  1. Click on Gear Icon at the top. Go to Setup.

  2. Select Object Manager → In the Quick find search and Select Lead.

  3. Select Fields and Relationships → Click New.

  4. Select Lookup Relationship → Click Next.

  5. For Related to option Select User as the Object → Click Next.

  6. Label the field as Lead Owner → Click Next.

  7. Check the Visibility for the required Profiles. For the Profiles which need only read access check both Visibility and Read Only.

  8. This field is created only to use in the screen flow and do not want to add to the page layout → Uncheck the checkbox and Click Save and New.

  9. For the second custom field, select Formula as Data Type → Click Next.

  10. Select Text as Data Type and Enter Field Label as Lead Owner  and Field Name(API Name) as Lead Owner Formula → Click Next.

  11. The Owner can be a Queue or an User. The below formula returns the non blank value of either of the Queue Name or the Owner's full name (concatenating first and last names).

    BLANKVALUE( Owner:Queue.QueueName ,  Owner:User.FirstName + " " +  Owner:User.LastName)

  12. Click Next.

  13. Select the Profiles to which you want to grant the access.

  14. Add the field to the Page Layout → Click Save.

CREATE CUSTOM NOTIFICATION

  1. In the Quick find search and  Select Custom Notification → Click New.

  2. You will see a popup. Enter Custom Notification Name as Change Lead Owner Notification → Under Supported channels Check Desktop and Mobile → Click Save.

CREATE EMAIL TEMPLATE

  1. From the Quick find search and  Select Classic Email Template → Click New Template.

  2. Select Custom (Without Using Classic Letterhead) radio option → click Next.

  3. Check on Available for Use Option → Enter Email Template Name as Lead Owner Change Template → Template Unique name (API Name) will populate  automatically.

  4. Add Subject as Lead Assigned, Click Next.

  5. Copy Paste the below content in HTML Template

    The Lead '<a href={!Lead.Name}'  has been assigned to you.

  6. For Text-Only Email Content click Copy text from HTML Version Button.

  7. It will show a warning message → Click Ok.

  8. Click Save.

CREATE AN EMAIL ALERT

  1. From the Quick find search and  Select Email Alerts → Click New Email Alert.

  2. Add Description as Email Alert for Lead Owner Change. Unique Name will be populated automatically.

  3. Select Object as Lead, For Email Template click the search icon and choose Lead Owner Change Template.

  4. For Recipient Type Select Owner.

  5. Under available recipients select Lead Owner and Click Add button.

  6. Click Save.

  7. Now The Email Alert is ready

CREATE SCREEN FLOW

  1. From the Quick find search and  Select Flows → Click New Flow.

  2. Select Screen flow → Click Create.

  3.   By default the layout is set to Auto Layout.

  4. Click New Resource on the left side.

  5. Select Resource Type as Variable → Enter API name as recordId → Select Data Type as Record → Select Object as  Lead → Check on Available for Input → Click Done.

  6. Select (+) icon → Select Screen Element.

  7. Name the Screen Element as Change Owner Screen → Check off Show Header. If needed, we can enter the header too.

  8. Under Configure footer Choose Use a Custom Label in Next (or) Finish Button → Enter Change Owner.

  9. Hide Previous Button and Pause button in footer.

  10. Drag and Drop Display Text Component onto the screen.

  11. Enter API name as CaptureLeadID → Insert {!recordId} in Resource.

  12. Click Set Component Visibility for the Display Text component→ Choose All Conditions Are Met (AND).

  13. Enter recordId>Lead ID Is Null True → Click Done.

  14. Drag and Drop Lookup component below to the Display Text Component.

  15. Enter LeadOwner as API name → Enter Lead_Owner__c as field API name (which is the API name of the custom lookup field we created) → Enter Owner  as Label → Enter Lead as Object API name →Select {!$GlobalConstant.True} in Required.

  16. Click Advanced → Check Manually assign variables. Select Record Id → Click New Resource.

  17. Select Variable as Resource Type → Select Text as  Data Type → Enter OwnerId as API name → Click Done.

  18. For the Record Name → Click New Resource.

  19. Select Variable as Resource Type → Select Text as Data Type as → Enter OwnerName as API name → Click Done.

  20. Drag and Drop Text component below to the lookup component.

  21. Enter Label as Reason → Check on Required.

  22. Drag and Drop checkbox component below to the Reason Component.

  23. Enter Label as Send Email Notification.

  24. Click Done.

  25. Click (+) icon → Select Update Records Element.

  26. Enter Update Lead as Label → Select Specify Conditions to identify records and set fields individually.

  27. Select Lead as Object → Select All Conditions Are Met (AND) → Enter filter condition as ID Equals to recordID > Lead ID.

  28. Under Set Values for the Lead Records, Select Reason_for_Owner_Change_c as the field → Select Reason as Value. 

  29. Click Add Field.

  30. Select Owner ID as the field → Select Owner ID variable as Value.

  31. Click Done.

  32. Click (+) icon → Select Get Records.

  33. Enter Label as Get Notification Type → Select Custom Notification Type as Object → Choose condition requirements as All Conditions Are Met (AND) → Choose Developer Name as Field, Equals as Operator and Change_Lead_Owner_Notification(API name of the custom notification we created) as Value.

  34. Choose Ascending as sort order → sort by Id → Choose only the First Record in How many records to Store → Choose Automatically store all fields in How to store Record Data.

  35. Click Done.

  36. Click (+) icon → Select Assignment Element.

  37. Enter Assign Lead Owner as Label. Under Set Variable Values,  Click on Variable and Click New Resource.

  38. Select Variable as Data Type → Enter LeadOwnerIds as Label → Select Text as Data Type → Check on Allow Multiple Values → Click Done.

    Note: This is a collection variable. Recipients for Custom Notifications expect collection.

  39. Choose the Add as Operator → Select Owner Id variable as Value.

  40. Click Done.

  41. Click (+) icon → Select Action Element.

  42. Enter Send in Search Actions → Choose Send Custom Notification.

  43. Enter Label as Notification for Lead Owner Change → Select Custom Notification Type ID From Get_Notoification_Type > Custom Notification Type Id.

  44. For the Notification Body, Click on New Resource.

  45. Select Text Template as Resource Type → Enter Notification Body as API name → By using insert Resource use lead field values and create Email Body → Click Done.

  46. For the Notification Title, Select New Resource.

  47. Select Resource type as Text Template → Enter API name as Notification_Title → Enter Lead Re-Assigned. In Body → Click Done.

  48. For the Recipient IDs → Select LeadOwnerIds collection variable.

  49. Check the Include button for Target ID and Add Lead Id.

  50. Click Done.

  51. Click (+) icon → Select Screen Component.

  52. Enter Label as End Screen → Check off Show Header.

  53. Expand Configure Footer → Choose Use a Custom Label in Next or Finish Button → Enter Done → Hide Previous and Pause buttons.

  54. Drag and Drop Display Text component onto the screen → Enter API name as EndScreen → Enter Lead Owner has been changed to {!OwnerName} as text value. (Select Owner name by inserting the resource).

  55. Click Done.

  56. Click (+) icon → Select Decision Element.

  57. Enter Label as Email Notification → Enter Outcomes detail Label as Send Email → Choose Send Email Notification Equals to True  → Click Done.

  58. Click (+) icon under the Send Email → Click Action Element.

  59. Select Type for Filter by  → Select Email Alert.

  60. In search email alerts, Select Email Alert for Lead Owner Change → Click Done.

  61. Enter Label as Email Alert → API Name will Auto populate.

  62. Select Lead ID in Record ID.

  63. Click Done.

  64. When a flow is launched from a custom button, the flow runs in User Context by default. Check this link for more information on which context a flow runs depending on the method of launch.

  65. The User who runs the screen flow should have access to the Custom Notification Type in order to send a custom In-app notification. But Profiles cannot be given access to Custom Notifications as of now.

  66. To overcome this issue we will run the flow in System context - with Sharing-Enforces Record Level Access. 

  67. When the flow runs in system context with sharing, the flow respects org-wide default settings, role hierarchies, sharing rules, manual sharing, teams, and territories. But it doesn’t respect object permissions, field-level access, or other permissions of the running user.

  68. Click Gear Icon at the top left corner.

  69. Click Show Advanced.

  70. Select System context - with Sharing-Enforces Record Level Access in How to Run the Flow.

  71. Click the Save button at the top right corner.

  72. Enter Flow Name as Lead Owner Change Screen Flow → Click Save.

  73. Click Activate.

CREATE CUSTOM ACTION BUTTON

  1. Go to Object Manager → In the Quick find search and Select Lead.

  2. Select Buttons, Links and Actions→ Click New Action.

  3. Select Action Type as Flow.

  4. Select Lead Owner Change Screen Flow → Enter Label as Change Owner.

  5. Go to any Lead record page → Click Gear icon → Click Edit Page.

  6. Select the Highlight Panel → Click Add Actions.

  7. Select Change Owner under Quick Actions → Click Done.

  8. Move the Change Owner button to the top.

  9. Click Save.

  10. Go to the previous Lead Record Page → Change Owner Button will be displayed on the page.

  11. Remove Standard Owner Field from the Lead Page Layout → Click Gear Icon → Click Edit Object.

  12. Select Page Layout → Select Lead Layout.

  13. Click (-) icon on the Standard Lead Owner field.

  14. Add Lead Owner Formula field in the place of Standard Lead Owner field in the Page Layout.

  15. Click Save.

Testing Flow : 

  1. Select any Lead Record → Currently this record owner is Saichand Ballagiri →  In the Lead Record Page Click Change Owner Button

  2. Select the new Owner → Add Reason for Changing Owner (Enter Lead is based on North Side) → Check on Send Email Notification (If it is checked it will send Mail to the new owner) → Also It sent In app notification to the new owner.

  3. Click Change Owner.

  4.  The screen displays that Lead Owner has been changed to Periakaruppan Ganesan → Click Done.

  5. The new Lead Owner will receive an In App notification mentioning a Lead has been Re-Assigned to him.

  6. You will receive Email Notification like below.

Note

  1. The Standard OwnerId field cannot be used in a Lookup Component in Screen flow. So a Custom lookup field was created and used in the screen flow.

WRAPPING IT UP

In this Blog we have covered how to add a reason when changing the owner of a lead record and send an In app Notification and Email to the New owner.

Leave a Comment

Your email address will not be published

← All Articles
Digital Biz Tech • May 10, 2022