Note from the author
Please let me know if you run the scripts and produce new results, so that we can confirm the validity of what I originally published. It would be great if you can also share any contradictions or different results that you encounter, so that the Salesforce community can always have an accurate and up-to-date reference for managing user licenses.
How do I use the scripts?
You should be comfortable with:
- Downloading files
- Creating and editing .csv files
- Running commands in the Command Prompt (Windows) or the shell (*nix)
You'll also need to have on your computer:
- A Salesforce org that allows you to create (not deploy) Apex. Typically this means a sandbox org or a Developer Edition org.
- Ruby. If you're on Windows, make life simple and run RailsInstaller.
- Nokogiri for Ruby
- The scripts. Easiest way is to just download this repo as a .zip file and extract it to your computer
Step 1. List all licenses available to you for testing
The ruby folder contains a sample UserLicense.csv file, which should list every user license available in your org to use for testing. To avoid errors, you should generate this list from your org using SOQL.
SELECT Name FROM UserLicense ORDER BY Name
Make sure you leave the Name column header in the UserLicense.csv file. The script assumes that this header is present and will skip the first row when executing.
Step 2. Create profiles in your org for testing purposes
TIP: All of the test profiles created have names that begin with "ApexUnit". If this will conflict with a real naming convention in your org, please abort this exercise.
Since you can't actually create profiles in Apex tests (at least in Winter '14 and API 29.0), you will need to create real profiles that will only be used for testing purposes.
This part should be pretty painless:
- Launch a command line interface (e.g., Command Prompt, Terminal)
- Change to the ruby folder for this project
> ruby create_new_profiles_package.rb
- Log into Workbench. You can skip this step and use any other Metadata API-compatible deployment tool if you want, but these instructions are written assuming you will use Workbench.
- Hover over the migration nav header, then click Deploy
- Select the "ApexUnit Profiles Package __.zip" file that was generated by the script, which should be in the same ruby folder
- Mark these checkboxes: Rollback On Error; Single Package; Run All Tests
- Click Next, then click Deploy
Step 3. Run the test and save the test log
TIP: As noted as a prerequisite, you must be able to create Apex in your org, because the test class used here cannot be deployed to a production org.
- Create a
UserLicenseTestApex class in your org, using the code from the src/classes/UserLicenseTest.class file
- Open the Developer Console in Salesforce
- Run the tests contained in the UserLicenseTest class
- Open the test results and download the log file
Step 4. Create a CSV file of the results
You're almost done! This last part is a bit tedious but manageable.
- Open the log file
- Find the
USER_DEBUGline that contains the raw CSV output of the results
- Copy all of the raw CSV output, then paste it into a new text file
- Save the text file as a .csv file
- Open the .csv file in Excel, pretty it up, and distribute!
Again, if you do succeed in running this script in your org, many people will appreciate your sharing the results back with the community.