back to blog
Enhance the standard Change Owner functionality
May 10 2022 • 40 min read

Business Requirement 

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

cof 1

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.


  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.

    cof 2

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

    cof 3

  3. Select Fields and Relationships → Click New.

    cof 4

  4. Select Lookup Relationship → Click Next.

    cof 5

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

    cof 6

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

    cof 7

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

    cof 8

  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.

    cof 9

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

    cof 10

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

    cof 11

  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)

    cof 12

  12. Click Next.

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

    cof 13

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

    cof 14


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

    cof 15

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

    cof 16


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

    cof 17

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

    cof 18

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

    cof 19

  4. Add Subject as Lead Assigned, Click Next.

    cof 20

  5. Copy Paste the below content in HTML Template

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

    cof 21

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

    cof 22

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

    cof 23

  8. Click Save.

    cof 24


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

    cof 25

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

    cof 26

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

    cof 27

  4. For Recipient Type Select Owner.

    cof 28

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

    cof 29

  6. Click Save.

    cof 30

  7. Now The Email Alert is ready


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

    cof 31

  2. Select Screen flow → Click Create.

    cof 32

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

    cof 33

  4. Click New Resource on the left side.

    cof 34

  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.

    cof 35

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

    cof 36

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

    cof 37

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

    cof 38

  9. Hide Previous Button and Pause button in footer.

    cof 39

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

    cof 40

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

    cof 41

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

    cof 42

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

    cof 43

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

    cof 44

  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.

    cof 45

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

    cof 46

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

    cof 47

  18. For the Record Name → Click New Resource.

    cof 48

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

    cof 49

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

    cof 50

  21. Enter Label as Reason → Check on Required.

    cof 51

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

    cof 52

  23. Enter Label as Send Email Notification.

    cof 53

  24. Click Done.

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

    cof 54

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

    cof 55

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

    cof 56

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

    cof 57

  29. Click Add Field.

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

    cof 58

  31. Click Done.

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

    cof 59

  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.

    cof 60

  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.

    cof 61

  35. Click Done.

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

    cof 62

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

    cof 63

  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.

    cof 64

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

    cof 65

  40. Click Done.

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

    cof 66

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

    cof 67

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

    cof 68

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

    cof 69

  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.

    cof 70

  46. For the Notification Title, Select New Resource.

    cof 71

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

    cof 72

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

    cof 73

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

    cof 74

  50. Click Done.

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

    cof 75

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

    cof 76

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

    cof 77

  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).

    cof 78

  55. Click Done.

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

    cof 79

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

    cof 80

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

    cof 81

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

    cof 82

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

    cof 83

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

  62. Select Lead ID in Record ID.

    cof 84

  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.

    cof 85

  69. Click Show Advanced.

    cof 86

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

    cof 87

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

    cof 88

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

    cof 89

  73. Click Activate.

    cof 90


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

    cof 91

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

    cof 92

  3. Select Action Type as Flow.

    cof 93

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

    cof 94

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

    cof 95

  6. Select the Highlight Panel → Click Add Actions.

    cof 96

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

    cof 97

  8. Move the Change Owner button to the top.

    cof 98

  9. Click Save.

    cof 99

  10. Go to the previous Lead Record PageChange Owner Button will be displayed on the page.

    cof 100

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

    cof 101

  12. Select Page Layout → Select Lead Layout.

    cof 102

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

    cof 103

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

    cof 104

  15. Click Save.

    cof 105

Testing Flow : 

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

    cof 106

  2. Select the new OwnerAdd 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.

    cof 107

  3. Click Change Owner.

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

    cof 108

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

    cof 109

    cof 110

  6. You will receive Email Notification like below.

    cof 111


  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.


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

© 2024 Digital Biz Tech