In Blog, Tips & Tricks
A Salesforce URL Hack is when we use the browser’s URL to pass information or have Salesforce do something beyond it’s normal functionality. Commonly the URL is placed in a custom button or link. A great is example is using a URL Hack to pre-select the email template when sending email within Salesforce.
Faithful readers of this faux newspaper already know my feelings about URL Hacks. They can be useful things, but they have their problematic issues. That’s why I prefer to use alternatives like publisher actions or something else.
There are somethings publisher actions cannot do (yet). For example, Creating a Contact Role at the same time as an Opportunity. So, with apologies to Shannon Hale for making her cry.

Considerations and Disclaimer

The biggest thing to consider is that URL Hacks are not officially supported by Salesforce. This means they may – and probably – will eventually break in some future update.

The other item to consider is there may be alternatives that will give us similar outcome, but are supported by the platform. We’ll talk about some of those options in a future post.

The other consideration is that this will add a Contact Role to the new Opportunity, but it will not set the role. It will mark it as the primary Contact Role.

URL Hack for Contact Roles

So here’s the URL hack /006/e?ent=Opportunity&
conid={!Contact.Id}

That’s the bare minimum that you need to get this to work. The first part /006/e? is basic URL for editing an Opportunity.

conid={!Contact.Id} this is the key parameter. conid prompts Salesforce to create a Contact Role with the provided Contact ID.

If you’re going to use a URL Hack, you might as well go all out. So let’s make it a bit more useful:
/006/e?lookupcmpgn=1&
retURL=%2F{!Contact.Id}&
cancelURL=%2F{!Contact.Id}&
RecordType=012E0000000DCnZ&
ent=Opportunity&
conid={!Contact.Id}&
opp6={!Contact.LeadSource}&
opp11="Prospect"&
opp3={!Account.Name}&
opp9={!TODAY()+30}

Let’s take a look at these one by one.

lookupcmpgn=1
This adds the campaigns to the Opportuntiy’s Campaign Influence. It also sets the most recent campaign as the Primary Campaign Source on the Opportunity.
retURL=%2F{!Contact.Id}&
cancelURL=%2F{!Contact.Id}&
These two items control what happens if the user clicks “Cancel” when creating the Opportunity. It’ll take the user back to the Contact.
RecordType=012E0000000DCnZ&
This will pre-select the Record Type of the Opportunity. Hard coding the Record Type is not ideal since IDs can change if Salesforce moves your org to a different instance or if you’re deploying from Sandbox and Production.
ent=Opportunity&
This isn’t necessarily required, but Salesforce puts it in URLs so I’m keeping it.
conid={!Contact.Id}&
Here’s our prompt to create a Contact Role
opp6={!Contact.LeadSource}&
opp6 sets the Lead Source of the Opportunity
opp11="Prospect"&
This is the Stage the Opportunity
opp3={!Account.Name}&
opp3 is the name of the Opportunity
opp9={!TODAY()+90}
Finally, opp9 is the Close Date.

You’ll notice each item ends with a & this let’s the browser know you’re setting additional parameters in the URL.

Wrap Up

There you have it. Use the power wisely. Remember, these aren’t officially supported by Salesforce.

Recommended Posts
Showing 7 comments
  • Francis Pindar (@radnip)
    Reply

    I can hear shannon crying now… also just to remember it won’t work on Salesforce1 mobile either, so better to get a coder to do it if you need mobile support.

    • Brian Kwong
      Reply

      good points Francis. That’s the trouble with unofficial functionality, it may not be supported in the new functionality that comes out.

  • Juul
    Reply

    Hi Brian, My users want to have a button to add a contact role on an opportunity via Salesforce1. Is that possible?

    • Brian Kwong
      Reply

      GREAT Question!

      Short Answer: No
      Longer answer: No. Salesforce1 doesn’t support Custom buttons and therefore it won’t support the URL Hack. Salesforce1 doesn’t support URL hacks in general. Can you get the same results in Salesforce1? Yes, Kind of. Sort of. It’ll require writing a custom publisher action that would create the Opportunity and then create the contact role. You might get away with not using a custom publisher action if you create a custom text field on the Opportunity for the “Contact Id” and then use a Publisher Action to fill that in as a default. So the user would use a publisher action to create the Opportunity and then we would have Process Builder/Flow create the contact role.

      I’ll have to try it out – sounds like a good post 🙂

  • Juul
    Reply

    Thanks for your quick reply. Let me know if you’ll get any further 🙂

  • Dimi Work
    Reply

    Hello , thanks for the post about opportunity,

    but do you have any idea why the URL in Quote does not work?
    the URL is:
    /0Q0/e?retURL={!Opportunity.Id}&oppid={!Opportunity.Id}&ent=Quote

    Can you create custom New Quote button on your sandbox and if it works please pass me the code.

    Thanks
    Dimi

    • Brian Kwong
      Reply

      Hey Dimi, thanks for the comment. I don’t have time right now to play with creating a custom quote button. I haven’t needed to creating one in the past so I’m not sure if there is anything special with it. I recommend you re ask your question over at success.salesforce.com in the answers section. You’ll get access to a lot more people than just me.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.