24 February 2014

If I were cloned which would I be, I, myself, yours truly, or me?

While talking with salesforce administrators, I often get the request to be able to clone a user. It's a common user provisioning flow in IT. As an administrator, it's easier to ask who a new user is most like rather than figure out all the settings and apps they need to get up and running in the organization as quickly as possible. There are even a couple of ideas on the ideaexchange and answers forum about it.

Cloning a user has three simple requirements:
  1. I should be able to provision a new user by creating a copy of an existing one.
  2. I should only have to provide the minimal information necessary for the clone to take place. 
  3. The new user should include the right level of access (public groups and permission sets) and apps necessary to get them up and running as soon as possible.
Almost everything I need to clone a user can be done with the app building tools on the salesforce platform.

The first requirement is pretty easy. I just need to easily search for an existing user to set as my source user.

It turns out I only need three user fields to create a unique clone or target user for the second requirement: first name, last name, and email address. Everything else can either be assumed based on that information or copied directly from the source user.

The third requirement is the tough one. Cloning a parent object is pretty easy. There are lots of articles and hacks like Salesforce: Clone Records Using a Custom Button or Link or Clone a User In Salesforce.com Without Apex. However the user object is unique and there are a number of additional hurdles to overcome when cloning.

Last summer I pitched the idea to bring a summer intern on board to build a sample Apex app that could simplify some of the clone user flow. Ian Dalton came on board and built out the majority of Apex we needed to demonstrate that it was possible. I built out the rest to surface it as a force.com app with a simple interface.

The flow is pretty simple:
  1. search for a source user.
  2. enter the minimal information for the target user.
  3. click the clone button.
  4. click the newly created target user's link and view their record. You'll find the permission sets and public groups came over as well.

To try this out, download the sample code from my github repository.

The easiest way to install this project into your org is to make use of the workbench tool (http://workbench.developerforce.com).
  1. Download a ZIP of the repository.
  2. Open Workbench.
  3. Login to the desired organization with a user that has Modify All Data permission.
  4. Select Deploy from the migration menu and when prompted, choose your zip file and select 'Allow Missing Files' checkbox before deploying it.
  5. If you get an error that the deployment failed because package.xml cannot be found: unzip the cloneUser.zip file you downloaded and use the terminal to re-zip it (e.g. zip -r cloneUser.zip cloneUser) before retrying step 4.
To start using, just assign the CloneUser permission set to any administrator who should be able to clone users using this app.

Once the permission set is assigned, you should be able to select the app from the app picker and begin cloning. All that is required is a source user, a first name, last name, and an email address.

Building administrative apps like the ability to clone users easily is a great way to learn more about the salesforce platform and build value within your organization at the same time.

Additional Credits:
Title is from a poem 'On Cloning' by M M Marshall
Picture is from Deviantart by dandroid


  1. Hi Adam,
    This is a really great app. I installed it in one of our sandboxes and it works perfectly. The only issue I found is that one of my delegated admins was able to clone a user who has a role and profile not assigned to that delegated admin. Is there a setting I need to toggle to make sure that doesn't happen?

    Other than that, it's really great, and I think we can make use of it if we can work around the above issue.

    1. Hi Nate, Thanks for trying out the app! Delegated Administration doesn't follow the same access check as this app which relies just on whether you have access to the underlying apex class. If you assign the permission set, it grants access to clone *any* user, not just the ones that are part of the role hierarchy you're responsible for. Hope it works out for your other use cases! Thanks!


Note: Only a member of this blog may post a comment.