back to blog
Mass Transfer Opportunities in Salesforce
June 09 2023 • 30 min read

BUSINESS CHALLENGE

When all the open opportunities that belong to a previous user have to be transferred to a new user, the standard Mass Transfer Records feature supports the transfer of Accounts with related Opportunities but not just the Opportunities.

To overcome this issue we have created a screen flow that lets the users transfer the open Opportunities from an old user to a new user.

STEPS TO ACHIEVE THE REQUIREMENT

  1. Create Custom Fields (lookup and formula)
  2. Create a Screen Flow
  3. Create a List Button 
  4. Add button to the List View

CREATE  CUSTOM FIELDS

  1. From the home screen click on the Gear Icon at the top → Go to Setup.

mto 1

  1. Select Object Manager → In the Quick find search and select Opportunity.

  2. Select  Fields and Relationships → Click New.

mto 2

  1. Select Lookup Relationship → Click Next.

mto 3

  1. For Related to Option Select User as the Object → Click Next.

mto 4

  1. Enter Account Manager as the field label → Field Name(API Name) will be populated automatically.

mto 5

  1. Create a Custom field, select Formula as the data type → Click Next.

  1. Select Text as Data Type and Enter Field Label as Account Name and the Field Name(API Name) will be Auto populated → Click Next.

mto 7

  1. The following formula returns the Account Name in the formula field → Account.Name. Insert the required fields using the Insert Field button.

mto 8

  1. Click Next.

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

mto 10

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

  2. Create custom field , select Formula as Data Type → Click Next.

mto 11

  1. Select Text as Data Type and Enter Field Label as Owner Name and the Field Name(API Name) will be Auto populated → Click Next.

mto 12

  1. The below formula returns the Owner Name by combining the first name and last name.

mto 13

mto 14

  1. Click Next

CREATE SCREEN FLOW

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

mto 15

  1. Select Screen flow → Click Create.

mto 16

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

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

mto 17

  1. Drag and Drop Lookup Component onto the screen

mto 18

  1. Enter API Name as From_Owners and enter Field API Name as Account_Manager__c (any lookup fields API Name to the User object).

  2. Enter Label as From Owners and select Object API Name as Opportunity → Enter maximum selections 5.

mto 19

  1. Click Advanced → Check Use values from when the user last visited this Screen.

mto 20

  1. Name the Screen Element as Screen One → uncheck Show Header.

  2. Under Configure footer Choose Use a Custom Label in Next (or) Finish Button → Enter  Get Opportunities.

  3. Hide Previous button and Pause button in the footer.

mto 21

  1. Select (+) icon →Select Get Records element.

  2. Enter Get Opportunity as the Label. Select Object as Opportunity → Choose All Conditions Are Met (AND) for the condition requirements.

mto 22

  1. For the first condition choose OwnerId as the Field ,In as the Operator and  From_Owners > RecordId Collection as the value→ Add another condition as Stage Name Does Not Equal  Closed.

  2. Under Sort Opportunity Records choose Ascending as the sort order and sort by Id.

  3. Choose All Records for How many records to Store, select Choose fields and let salesforce do the rest for How to Store Record Data.

mto 23

  1. For Select Opportunity Fields to store in Variable add Stage Name, Close Date, Name, Account Name, Owner Name  and click Done.

mto 24

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

mto 25

  1. Enter Count All Opportunity as the Label. Under Set Variable Values, Click on Variable and Click New Resource.

  2. Select Variable as Data Type → Enter Opportunities_found as API Name → Select Number as Data Type → Enter 0 in Decimal Places → Click Done → Select Equals Count as the Operator → Set Opportunities from Get_Opportunity as Value → Click Done.

mto 26

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

  1. Name the Screen Element as Screen_Two → uncheck Show Header.

mto 28

  1. Under Configure footer choose Use the standard label for Next or Finish button and Previous button → hide the pause button.

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

  3. Enter API Name as Header_Two → Insert  Select Opportunities to change the Owner Opportunities Found: {!Opportunities_found} ( A maximum of 99 Opportunities can be selected) in Resource.

mto 29

  1. Drag and Drop Data Table Component onto the screen.

mto 30

  1. Enter Label as Opportunities and API Name will be Auto populated

  2. Click Configure Data Source → Select Opportunities from Get_Opportunities as Source Collection → Click on Configure Rows → Select Multiple Selection Mode → Enter 1 in Minimum Selection and Enter 99 in Maximum Selection 

mto 31

30.Click Configure Columns and Select the fields Name, Owner Name, Account Name, Stage and Close Date.

mto 32

  1. Click Advanced → Check Use values from when the user last visited this screen → click Done.

  1. Click (+) icon , Select Screen Element.

mto 34

  1. Enter Label as Third_Screen and API Name will be auto populated → uncheck show Header.

mto 35

  1. Drag and Drop the Lookup Component onto the Screen.

  2. Enter API Name as To_Owner and Field API Name as Account_Manager__c and Label as To Owner → Enter Object API Name as Opportunity.

mto 36

  1. Click Advanced → Check  Use values from when the user last visited this Screen.

mto 37

  1. Under Configure Footer → Check Use the standard label for Next or Finish button and Previous buttonHide Pause button → Click Done.

  2. Select (+) icon ,Click the Assignment Element.

  3. Enter Label as Getting Collection Count. Under set Variable Values, Click on Variable and Click New Resource.

  4. Select Variable as Data Type → Enter Selected_Oppty_Count as API Name → Select Number as Data Type → Enter Decimal Value as 0 → Click Done → Select Equal Count as Operator and Value as Opportunities > Selected Rows → Click Done.

mto 38

  1. Select (+) icon, Click the Screen Element.

  2. Enter Label as Fourth Screen and API Name will be auto populated → Check off show Header

mto 39

  1. Drag and Display Display Text Component onto the screen.

  2. Enter API Name as Conformation_Message → Insert {!Selected_Oppty_Count} Opportunities will be transferred to {!To_Owner.recordName}.

mto 40

  1. Select Set Component Visibility → Choose Always.

  1. Under Configure footer → Choose Use a Custom Label → Add Confirm to the Next or Finish button label → Check Use the standard label for Previous button and Hide Pause button → Click Done.

  2. Click (+) icon, Select Loop Element.

mto 42

  1. Label the Loop as Loop Selected Opportunity and API Name will be auto populated → Under select Collection Variable → Enter {!Opportunities.SelectedRows} → Check First item to Last item → Click Done.

mto 43

  1. Click (+) icon, Select the Assignment Element

  2. Enter Label as Assign New Owner → Under Set Variable Values → Select Variable as {!Loop_Selected_Opportunity.OwnerId}, Select Equals as the Operator and Value as To_Owner>Record ID → Click Done.

mto 44

  1. Click (+) icon, Select the Update Record Element.

  2. Enter Label as Update Opportunity → Select Use the IDs and all field values from a record or record collection → Under Select Record(s) to Update → Select the Record Collection as Current Item from Loop Loop_Selected_Opportunity → Click Done.

mto 45

  1. Click (+) icon, Select the Assignment Element.

  2. Enter Label as Updated Record Collection → Under Set Variable Values, Click on Variable and Click New Resource.

  3. Select Variable as Data Type → Enter Updated_Opportunity_Collection as API Name → Select Record as Data Type → To make it Collection, Check the Allow multiple values checkbox → Select Object as Opportunity → Click Done.

mto 46

  1. Select Add as Operator and Values as Current Item from Loop {!Loop_Selected_Opportunity} → Click Done.

  2. Click (+) icon, Select the Assignment Element.

  3. Enter Label as Count Updated Records → API Name will be Auto populated.

  4. Under Set Variable Values, Select Variable, Click New Resource → Select Variable as Data Type → Enter API Name as Updated_Records_Count and Select Number as Data Type → Set the Decimal Places as 0 → Click Done.

mto 47

  1. Click on the Update Records, Select Add Fault Path.

mto 48

  1. Click (+) Icon on the Fault Path, Select the Assignment Element → Enter Label as Error Record Collection.

mto 49

  1. Under Set Variable Values, Click Variable , Click New Resource → Select Variable as Data Type → Enter API Name as Error_Opty_record_Collection.

  2. Enter Record as Data Type → To make it a Collection, Check the Allow multiple values checkbox → Select Object as Opportunity → Click Done.

  3. Select Add as Operator and Values as {!Loop_Selected_Opportunity} → Click Done.

mto 50

  1. Click (+) icon, select the Assignment Element

  2. Enter Label as Count Error Record → Under Set Variable Values → Click Variable → Select New Resource → Select Variable as Data Type → Enter API Name as records_with_error, Select Number as Data Type → Set Decimal Values as 0 → Click Done.

  3. Select Equals Count as Operator and Values as {!Error_Opty_record_Collection} → Click Done.

mto 51

  1. Click (+) icon, Select the Assignment Element.

  2. Enter Label as Failure and Id Collection Assignment → Under Set Variable Values → Click Variable → Select New Resource → Select Variable as Data Type → Enter API Name as Failure_and_Id_Collection → Select Text as Data Type → To make it a Collection, Check the Allow multiple values Checkbox → Click Done.  Select Add as operator and value as Fault Formula With ID.

mto 52

  1. Click (+) icon, Select Connect to Element and Click on the Loop Element.

  2. Click (+) icon, Select Decision Element.

  3. Enter Label as Check Error Collection and API Name will be Auto Populated → Under Outcome details → Enter Label as Error Collection has Records → Select All Conditions Are Met (AND).

  4. Select New Resource → Select Variable as Data Type → Enter API Name as Error_Opty_record_Collection → Select Data Type as Record and To make it a Collection, Check the Allow multiple Values Checkbox → Select Object as Opportunity → Click Done.

  5. Select Is Null as  Operator and Select Values as Global Constant False → Click Done.

mto 53

  1. Click (+) icon in the Error Collection Records path, Select Screen Element.

  2. Enter Screen Label as Fifth Screen with error and API Name will be auto populated → uncheck Show Header.

mto 54

  1. Drag and Drop the Display Text Component onto the Screen.

mto 55

  1. Enter API Name as Success_Message and Insert {Selected_Oppty_Count} “Opportunities Selected {!Updated_Records_Count} Opportunities have been successfully transferred to {!To_Owner.record Name} {!records_got_error} Opportunities failed” as Resource → Click Set Component Visibility → Choose Always.

  1. Under Configure Footer → Check Use the Standard Label for Next or Finish button and Hide Previous and Pause button → Click Done.

mto 57

  1. Click (+) icon, Select Screen Element.

  2. Enter Screen Label as Error Record Display and uncheck Show Header.

mto 58

  1. Drag and Drop the Display Text Component onto the screen → Enter API Name as Error_List → Insert a resources as Failed Opportunities→ Click Set Component Visibility→ Choose Always.

mto 59

  1. Drag and Drop the Data Table Component onto the Screen → Enter API Name as error_record_list and Label as Data Table → Under Configure Data Source→ Select {!Error_Opty_record_Collection} as Source Collection → Click on Configure Rows → Select View Only.

mto 60

  1. Click Configure Columns and Select Fields Name, Owner Name, Account Name, Stage → Click Set Component Visibility→ Select Always.

mto 61

mto 62

  1. Click Advanced → Check Use Values from when the user last visited this Screen.

  2. Under Configure Footer → Check Use the Custom Label for Next or Finish button as Show Errors and  Check Use the Standard Label for Previous button and Hide for Pause button.

mto 63

  1. Click (+) icon, Select Screen Element.

  2. Enter Screen Label as List_of_Error_Screen and Check Off Show Header.

mto 64

  1. Drag and Drop the Display Text Component onto the Screen

  2. Enter API Name as Reason_for_Error and Insert Opportunities with Error as Resource → Drag and Drop the Display Text Component onto the Screen.

mto 65

  1. Enter API Name as Display_List_error and Insert {!Failure_and_Id_Collection} as Resource → Click Set Component Visibility→ Select Always.

mto 66

  1. Under Configure Footer → Check Use the Standard Label for Next or Finish button and Hide Previous and Pause button → Click Done.

mto 67

  1. In Default Outcome Path ,Click(+) icon, Select Screen Element.

  2. Enter Screen Label as Fifth Screen Without error and API Name will be auto populated →uncheck Show Header.

  3. Drag and Drop the Display Text Component onto the Screen.

  4. Enter API Name as Success_Message 1 and Insert {!Selected_Oppty_Count} Opportunities Selected {!Updated_Records_Count} Opportunities have been Successfully transferred to {!To_Owner.recordName}.

mto 68

  1. Click Set Component Visibility → Select Always.

mto 69

  1. Under Configure Footer → Check Use the Standard Label for Next or Finish button and Hide Previous and Pause button → Click Done.

mto 70

CREATE A LIST BUTTON

  1. Select Object Manager → In the Quick find search and select Opportunity.

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

mto 71

  1. Enter Label as Mass Transfer Opportunity and Name will be auto populated

  2. Select List Button as Display Type → Check Display Checkboxes→ Select Behaviour as Display in Existing window with sidebar and Select URL as Content Source.

  3. Copy and Paste the flow URL and add a return URL. /flow/Mass_Transfer_Opportunity_Flow?retUrl=/006/o → Click Save.

mto 72

Here /006/o returns the user to the recently viewed opportunities list view once the flow has finished.

ADD BUTTON TO THE LIST VIEW

  1. Select Object Manager → In the Quick find search and select Opportunity.

mto 73

  1. Select List View Button Layout → In Custom Button Click Mass Transfer Opportunity in Available Button and Add it to Selected Buttons → Click Save.

mto 74

TESTING

Go to the Opportunities tab and click the button Mass Transfer Opportunity . choose a user in the From Owner, click Get Opportunities, Select the Opportunity Records and then transfer the records to the new user to whom you want to transfer. You will be able to see the failed records if there are any.

WRAPPING IT UP

In this blog we have covered how to mass transfer Opportunity records from one user to another user using a screen flow.

Leave a Comment

Your email address will not be published

© 2024 Digital Biz Tech