Clone a User in Salesforce.com without APEX!

I cannot for the life of me figure out why Salesforce wants to make it so hard for you to clone a user. Sure you could write a bunch of fancy APEX code, but how about a simpler solution?

advertisement

The Problem

Why oh why can +Salesforce  not give us a Clone button on a user record? It would make life much more simple. Ever had to open up two tabs in your browser just so you can figure out which role and profile to use? Or copy and paste information like Company Name, Address and Department?

The Solution

I have put together a solution for this does not require APEX, does not need unit tests and code coverage and doesn’t even need a VisualForce page. Simply add a formula field and a custom link with a little JavaScript and you will be cloning users in record time.
There are two main parts of this solution but before we being, we need to get one thing that might be unique to your org. This is the 15 (not the 18) digit ID for the “Salesforce” license type. The easiest way I found to get this is by navigating to the New User page and using an inspection tool like Firebug for Firefox, the Chrome Developer Tool or IE’s Developer Tool to find the html element that represents the “Salesforce” option in the “User License” picklist and copying the value.

Part 0 – Get your orgs Salesforce License Type ID

I’m using +Google Chrome here, but the instructions are pretty much the same in other browsers. First go the new user page and locate the field called “User License”. Right click on the picklist (not the label) and select “inspect element” from the menu. One you have selected the picklist, expand the “<select>” element in the console. Find the “<option>” for “Salesforce” and copy the value attribute.

 If you are currently out of Salesforce licenses, you will not see this option. You will need to go to the edit screen of an existing user who has the Salesforce User License and inspect the picklist from there.

Part 1 – Create a Formula Field on the user object

  1. Click on “Setup”
  2. Click the [>] next to “Customize”
  3. Click the [>] next to “Users”
  4. Click on “Fields”
  5. In the “User Custom Fields” section click “New”
  6. For the Data Type, select “Formula”
  7. You can name the field whatever you like. I called mine “CloneUserParams”
  8. Select “Text” as the “Formula Return Type”
  9. Paste the following code into the formula
  10. Be sure and replace the ID in the first line with the one you copied from part 0
  11. Click Next
  12. Click Next
  13. I would not recommend adding this field to the page layout, so I would uncheck the “add field” checkbox and click “Save”

So what the heck is all of this? What we are doing here is building a big long string of query parameters that we will pass into the new user page. To make things easier to read, I’ve placed each field value on a seperate line. Each line should should start with an “&”, followed by the field ID (Click here for a list of field IDs and labels) on the new user page, then an “=” and lastly the value you want the field to be. You will notice that some of the fields use the value of the current record such as CompanyName so once the formula is evaluated it will pass the value of the current records Company Name to the new user page. However, not all fields are available in the formula editor so some will need to be hard coded.

For Example: The field “info_email” is a checkbox to denote whether or not users receive the newsletter. In the code above, I hard coded “1” as the value. “1” means checked, “0” means unchecked. I wish this could be more dynamic, but it is what it is. 🙁

Now, moving on the the special fields and how we handle them. There are several picklists on the new user page such as “Time Zone” and “Local” which we can optionally set. If you choose to leave those fields off the formula above, they will just use the default values. However, if you choose to hard code a value other than the default you will need to pass the value attribute of the <option> tag. Use can inspect the element in the browser much like we did earlier, or you can Click here to view a list of the values I have complied.

Part 2 – Create a Custom Link on the user object

  1. Click on “Setup”
  2. Click the [>] next to “Customize”
  3. Click the [>] next to “Users”
  4. Click on “Custom Links”
  5. Click on “New”
  6. In the Label field type “Clone User”
  7. In the “Behavior” picklist, select “Execute JavaScript”
  8. In the “Content Source” leave “OnClick JavaScript” selected
  9. Paste in the following JavaScript and click “Save”
This script does three things. First, it asked the user to provide the bare minimum of data (First Name, Last Name and Email Address). If you feel the need, you could expand this to ask for things like employee number or phone number or what have you. Secondly, it combines the field data generated by this script with the data from the formula field we just created and builds a long string of text which represents the new user setup page URL with query parameter to populate all the fields. Lastly, it redirects your browser to the URL it constructed.

Part 2.1 – Add the new custom link to the page layout.

  1. Click on “Setup”
  2. Click the [>] next to “Customize”
  3. Click the [>] next to “Users”
  4. Click on “Page Layouts”
  5. Click the “Edit” link next to the page layout you would like to add the custom link to
  6. In the toolbox at the top of the page select “Custom Links”
  7. Drag the new clone user link into the custom links section on the page layout
  8. Click “Save”

And that’s it! I hope you were able to follow along and please understand this is not a perfect solution, but with a little tweaking to fit your org’s individual needs, it can be pretty darn close. If you’re having trouble getting it to work, feel free to leave me a comment and I will do my best to help you out. Happy Cloning!

advertisement

Leave a Reply