Avoiding Hard Coded URLs

Hopefully you know that hard coding links in Salesforce is a no-no. You might one day be migrated from one instance to another (NA1 to NA9999, or whatever they are up to these days). You also want to make sure that your links work in all your sandboxes. There is nothing worse than clicking on a link in a sandbox and all of a sudden you are in production!

First of all, I recommend that you implement My Domain. This means that you won’t have to worry about moving from one instance to another. Plus you need it on to use Lightning Components. You want those, right?

For the most part within Salesforce, you can just avoid the beginning part of the URL and use relative URLs. So, a URL button that takes you to a Visualforce page can just have ‘/apex/MyPage’.

The first “gotcha” is with managed packages. If you want to link to pages in a managed package, then you can still use a relative URL. Just use the format of ‘/apex/NAMESPACE__ManagedPage’.

Another good trick is to use the URLFOR function within Visualforce. This future proofs your pages so that if Salesforce ever changes the URL scheme (hello, Lightning), everything will still work. For example, to get the link to edit an account, I can use the following syntax.

{!URLFOR($Action.Account.Edit, account.id)}

Email templates are another tricky part of links. Since the email is being sent out, you can’t use relative URLs. You need to link into your instance. For the object that is triggering the email, you can use the merge field called Detail Link. This looks like {!Opportunity.Link}.

But what if you want to provide a link in your email to a related record? For example, an email gets sent from an opportunity, but you want a link to the account? First, let’s create a formula field on the object that will trigger the email and call it Base URL and make it a text formula field with the following formula:

LEFT($Api.Partner_Server_URL_360, FIND( '/services', $Api.Partner_Server_URL_360))

You can now use this formula field in your email templates to link to other records or Visualforce pages. So, from an opportunity email, the merge field would be: {!Opportunity.Base_URL__c}{!Opportunity.AccountId}.

By implementing these changes, you can be assured your links will always go to the correct instance.

Salesforce Productivity With Chrome Extensions

I’ve seen several posts recently about Chrome extensions that help with your productivity in Salesforce. Here are a few I use every day.

Boostr for Salesforce

This new extension has several features. My favorite is that it removes the placeholder text from the search box in setup. How many times have you clicked into that box before the page finishes loading?

Salesforce Admin Check All

This handy little extension adds a checkbox at the top of admin page lists so you can quickly grant access to a big list of fields.

Salesforce API Field Names

I have mixed results with this extension. When it works, it replaces the labels on a page with the API names. It doesn’t work on feed based layouts and sometimes the order gets off. I haven’t quite figured out the reason why.

Salesforce Colored Favicons

If you ever have multiple orgs open at once, this extension changes your favicon different colors based on the instance you are on. This lets you easily know if you are in production or a sandbox.

Salesforce Quick Login As

I’ve saved my favorite for last. You can login as another user from any page in Salesforce and it takes you directly to that page as the user. No more going to setup, finding the user, logging in and then navigating to the page you want to look at.


Deleting a Single Item From the Recycle Bin

Sometimes you just want to remove a single item or a subset of items from the recycle bin without emptying the entire thing. I found this long-standing idea on IdeaExchange, and then realized I could do it in Apex.

First step is to find the Id of the record you want deleted from the recycle bin. I use workbench to create my SOQL query and query deleted items. Be sure to select the option to include deleted and archived records. Here’s a query to get the IDs of deleted cases.

select id from case where isdeleted = true

Once I have the ID, then I can use workbench to execute anonymous Apex. Just put a comma separated list of Ids in the List:

Database.emptyRecycleBin(new List<Id> {'500U000000IonltIAB'});