Hi and welcome to another great tutorial! I’m going to show you the exact step-by-step process on how to mass transfer records from one user to another in Salesforce. To accomplish this task I’ll be using the “Developers Console”.

For those who are unfamiliar with Developers Console – here is an awesome trailhead that you can take to get familiar.

Alright, so before we get started I’d like to point out that there is a standard tool to mass transfer records from one user to another. Here is a help article on that. However, I’ve found some limitations that were a dealbreaker for me. For example, I can’t use fields from related objects to filter the data. Also, I can’t transfer more than 200 records at a time.

Salesforce | Mass Transfer Records with Developers Console

Anyways, if for some reason the standard tool does not work for you, this approach should do the trick. Aside from transferring records, you could use this method for all kinds of data manipulations: create, update, delete records in Salesforce.

STEP 1: Launch Developers Console

Go ahead and click Setup -> Developers Console. Make sure that you allow pop-ups on a page. A new browser window should show up.

Launch Developers Console Salesforce

Here is how the Developers Console looks like. Now we just need to get to a window that can execute our simple apex script.

Salesforce | Mass Transfer Records with Developers Console

From the top menu go ahead and click ‘Debug‘ -> ‘Open Execute Annonymous Window‘. It will open a smaller window where we’ll be pasting our apex code to transfer records.

Salesforce | Mass Transfer Records with Developers Console

That smaller window will be used to execute our apex code. Please see below.

Developers Console Execute anonymous window Salesforce

Step 2: Write an Apex Script

Alright, let’s say we need to transfer all opportunity records from inactive users. To do so, we just need a very simple SOQL query and update statement. Please see below:

Copy to Clipboard

I’ve added some comments to the code. But essentially we look for all records that match our search criteria. Then we do a FOR loop to replace owner IDs for each record. Lastly, we perform an update in the database.

XXXXXXXXXXXXXXXXXX – is the user ID in Salesforce. Let’s say you’ve identified a user you’d like to transfer records to. Go to any record that is owned by that user and click on its name. It will take you to a user page. From there you just need to find the Salesforce ID in the URL as shown below:

Salesforce User ID

Once everything is set and ready to go just hit ‘Execute’ and it will update all the records. That’s it. This very simple example shows how you can alter the data in your SF org very efficiently.

Depending on how many records you are trying to update, you may run into ‘Apex CPU time limit exceeded’ error. That means you are exceeding governor limits for processing time. To resolve this you just need to use LIMIT for your SOQL Query. For example:

Copy to Clipboard

This will limit the amount of returned opportunities to 50. This means if you have 146 records to update, you’ll need to run your script 3 times.

You may also encounter errors due to validation rules. You’ll have to either disable validation rules, fix invalid records or filter them out of your script in the first place.

IMPORTANT PRECAUTIONS

Like I’ve said earlier, this a very simple way to update records in SF. However, make sure you are 100% sure of what you doing.

  • Double-check all scripts that you are going to execute.
  • Comment all insert/update/delete statements and verify that your queries return the correct amount of records.
  • Make a SOQL query and then run a quick report to cross-check the number of records.
  • Use debug logs when necessary.

All in all, don’t **** up! Good luck and may the Salesforce be with you!

Salesforce Developer Meme
0 0 vote
Article Rating