This one’s for you, coffee-shop hopping Force.com developers who go to make some changes to your code in Eclipse and — blocked! Login must use Security Token! Uggh. But I hate Security Tokens – sure, sure, it makes way more sense to use them. Definitely a best practice. But, well, sometimes I’m lazy. I confess – I very often just use Trusted IP Ranges.
So, for those of you out there that have been in my situation, and like me don’t like entering Security Tokens into your Eclipse, SOQLExplorer, Data Loader, etc., and prefer to just use Trusted IP Ranges and basic username/password, I’m guessing you find yourselves doing this over and over again:
- Show up at Coffee Shop you haven’t been to before – or at which you’ve never done any development on a particular Force.com project / org.
- Login to Eclipse.
- Try to save something.
- Fail – you’re at a non-trusted location and you’re not using the Security Token!
- Login to Salesforce.com.
- Go to your Personal Information.
- Copy the IP address from your most recent login.
- Go to Network Access, and add a Trusted IP Range, and paste in the IP Address from Step 7 into both Start and End IP Address. Click Save.
- Go back to Eclipse and resave.
Wish there was a way to do this faster?
There is – here’s a little convenience script for the uber-lazy, coffee-shop hopping, Security Token-hating Force.com developer – if there are any of you out there other than me, this if for you!
The Idea: a one-click link in a Home Page Component
My idea: create a Home Page Component for the Left Sidebar that, in one-click, adds a new Trusted IP Range corresponding to the current IP you’re at.
Problem 2: how to quickly create a new Trusted IP Range? There’s no API access to the Trusted IP Range object (which is probably a good thing from a security perspective 🙂
Problem 1 Solution: Use JSONP + an External Site
Problem 2 Solution: URL Redirect with params passed in
One thing I love about the Force.com platform is that almost every action you might want to take, whether for modification of metadata or data, can be initiated by going to a specific URL. To create a new Account record, you go to “/001/e”. To view all users, you go to “/005”. And almost any field on a particular page can be pre-populated by passing a corresponding URL Parameter (although these are not always consistent). And so it is with Trusted IP Ranges – to create a new Trusted IP Range, head to “/05G/e”. And to pre-populate the Start and End IP Address, you simply have to pass in the right query string parameters: “IpStartAddress” and “IpEndAddress”.
All together now! The final product.
So here’s the final solution:
- Go to Setup > Home Page Components > Custom Components.
- Click New.
- Enter a name, e.g. “Add IP to Trusted Ranges”, and select “HTML Area” as the type. Click Next.
- For Position, select “Narrow (Left) Column”.
- Click the “Show HTML” checkbox on the far right, and enter the following code for the body, then click Save.
6. Go to Home Page Layouts, and add this Home Page Component to your layout as a System Admin.
Now return to your home page, and voila! Here’s what you’ve got: a link that, when you click, it takes you to a prepopulated new Trusted IP Range – just click Save, and boom, get back to Eclipse and save your code!
How does it work?
Nothing crazy here, but I’ll step through the code anyhow:
- Load jQuery from the Google API’s CDN, so that we can use the handy getJSON() method.
- In our anonymous callback function, we do a URL redirect, passing in our current IP address as both the Start and End IP Address as parameters to the new Trusted IP Address page:
- Then we click Save, and we’re done!