Salesforce URL Hacking – Tutorial

After briefly covering what Salesforce URL Hacking is in my 4 Clever Hacks with Salesforce buttons post I decided that this would require a separate post being the beast of a topic that it is! But please don’t be put off by that statement, URL Hacking does take some learning but it is by no means an advanced topic or require you to be a developer. It will also teach you a lot about how URL’s work and help you do similar techniques in Salesforce and other systems.

As a quick recap – URL hacking is the process of pre-populating data in a new record with data from a record you are currently working off using a custom button to launch this new record. Check out my 4 Clever Hacks post above for an example, as  I will be using a similar example through this tutorial.  In a nutshell though I will be populating a new custom object called Resource Request from data in the Opportunity.

Step 1 – Creating a button and adding it to your page layout

The best place to start with creating a custom button to URL hack is to actually create the framework and add the button to the page layout so we can start testing after each step is completed. So go to your object and Click “New Button or Link” in the section Buttons, Links & Actions. Lets give our new button a name and select List Button. This means it can be placed in a related list and not on top of a record. We also want to make sure we have the behaviour set as the below and the content source as URL.

Screen Shot 2015-02-06 at 16.39.31As we want this button to launch our object and fill it with information, lets deal with the actual launching of the object first. The button we’re creating already presumes that we want to launch information inside of Salesforce, so hidden away out of site of the text box you will with your URL will be “https://na15.salesforce.com/” with whatever instance of Salesforce you are on. This means we only need to fill in data after the /.

The URL to actually launch our object looks a bit like this “/a0U/e”. The three letter code is your object code. You can find out your object code by creating a new record and looking at the first part of the URL, mine looks a bit like this. The “e” refers to edit, which means we are going to the edit page of this object.

https://na15.salesforce.com/a0U/e?

So copy that part after the .com and up to ? and paste it into your new custom button you have created so it looks like this.

Screen Shot 2015-02-06 at 16.51.51

We’re now ready to add this to our page layout and launch it! To do this were going to need to go to the master object where this button is going to be launched from. In my example this is the opportunity. Edit this page layout and scroll down to your related list. You then want to hit the spanner.

Screen Shot 2015-02-06 at 16.53.14

Once here you can click on the Buttons tab and move across your new button to the selected side.

Screen Shot 2015-02-06 at 16.53.46We’re done! Give your button a click. It should launch into the edit page for your new object.

Step 2 – Pre-populating some basic text values

Now we’ve set up our basic custom button that launches our edit page for the new record we want to create, lets start populating some data. The reason this step is to populate some basic text values, is because the way to populate Lookup fields is very slightly different.

So to start off pre-populating text values we need two things. The ID of the field we wish to populate and the value of which we would like to populate this with.

1. To get the ID of the field we wish to populate go to the relevant object in setup and click on the field we wish to populate. If you check out the URL when you’re on this page, you can see the unique ID given to this field.

https://na15.salesforce.com/00Ni000000EpsgY?setupid=CustomObjects

2. The value of which we would like to populate this with is found in the form of a merge field. These can be explored on the custom button page and looks like the below. As I am working off an Opportunity I can grab fields from the Account and Opportunity page because of the relationship.

Screen Shot 2015-02-08 at 13.37.20

Now, to turn this into something that actually works! Lets go to our custom button editing page and enter a “?” after our little URL. This acts as a separator and will allow us to enter the next part. The next part will just require you to enter the ID of the field you grabbed earlier with “=” and then the merge field value.

/a0U/e?00Ni000000EpsgY={!Opportunity.Description}

If you click on your list view button now, you will be hopefully able to see a pre-populated value in your specified field. If this does not work be sure to check out your URL on the page to make sure it looks correct. My button that I have just made will look like this..

https://na15.salesforce.com/a0U/e?00Ni000000EpsgY=This+is+a+test

As you can see we have our field URL and then the value afterwards. If the value is not present for any reason you can presume that either data is not in that field at the moment or the merge field is wrong or not accessible.

Step 3 – Pre-populating lookup values

You may have noticed that if you are following a similar example to mine, your lookup value will not be pre-populating like the default “New” button does. This is because behind that new button, Salesforce is bringing over the value from the previous object, as our button is fresh, we will need to do this ourselves (and with any other lookup values we have). They do differ slightly from basic text values which I will explain below.

To populate a Lookup value we need the field ID as before but this time we need to add CF to the front of the ID so it looks something like this – CF00Ni000000EpsgO. This is required when populating a custom lookup field.  The first part to populate a lookup value is to grab the name of the record we are populating. So using the method before but with the added CF you can expect your button URL to look like this

/a0U/e?CF00Ni000000EpsgO={!Opportunity.Name}

The next step is to grab the ID of the record we wish to populate. This time though, we are going to add “_lkid” to the end of our field ID (plus the CF we added on earlier). This lkid parameter is telling Salesforce this is a lookup field. So it looks a bit like this.

/a0U/e?CF00Ni000000EpsgO={!Opportunity.Name}&CF00Ni000000EpsgO_lkid={!Opportunity.Id}

Again nothing too fancy we’ve just added some extra parts to the ID and referenced this field twice, grabbing the ID and the Name of the record.  Please note the “&” used to separate the URL when referencing different fields. You can also see this being used below where I have the full URL used for this demonstration.

/a0U/e?CF00Ni000000EpsgO={!Opportunity.Name}&CF00Ni000000EpsgO_lkid={!Opportunity.Id}&00Ni000000EpsgY={!Opportunity.Description}

Bonus Tips

  • As mentioned earlier, if something isn’t working, always checkout the URL on your object after you click your custom button. This will show you whether data is getting as far as being populated into the URL.
  • You should always add &retURL={!Opportunity.Id} to your button. Where Opportunity.ID is the ID of your master object. This will make sure your return to this object if you press cancel while creating a record.
  • URL hacking may not be the best thing to use if you have a very complex process that requires a lot of data to be transferred. Please look to APEX in these circumstances.
  • If you have multiple record types, you can easily pass in the ID of the record type using this format – &RecordType=abc. With abc being a fixed value or possibly a merge field with your Record Type ID (This can be found on the record type page)

 

SalesforceBenHeader

Subscribe To The Monthly Newsletter

No Spam. No Rubbish. Just great content from the Salesforce Industry.

You have Successfully Subscribed!

60 thoughts on “Salesforce URL Hacking – Tutorial

    1. ben@ben-mccarthy.com

      Reply

      Hi David,

      Yup! This can be done for nearly any object you can place a button on. All you have to do is built the button as per the instructions but getting the Case URL, which I believe looks a little like this… /500/e?

      Thanks!

      Ben

  1. Hi,
    here is the URL i when I click on “new email”:

    _ui/core/email/author/EmailAuthor?p2_lkid=003j000000C5Xo7&rtype=003&p3_lkid=500j0000002TVF1&retURL=%2F500j0000002TVF1

    any ideas? thanks for putting up your site!

  2. I’m creating a New button for a child record. The child records have several lookup fields that are not on the parent.

    I’d like to hardcode into the URL a value (id) for a lookup field.

    Here is the section,
    …&CF000NF0000008yBTy__lkid=a2tZ0000000HKzN&CF000NF0000008yBTy={!rstk__rtproc__c.Name}

    where:
    00NF0000008yBTy = the field i want to populate on the child,
    a2tZ0000000HKzN = hardcoded lookup record ID
    {!rstk__rtproc__c.Name} = the name of the record being looked up.

    Help would be awesome!

    1. ben@ben-mccarthy.com

      Reply

      Hi Jeremy,

      Your URL looks fine and you can absolutely hard code the values. Is this not working at the moment?

  3. Not working! I don’t know why it won’t populate on the screen.

    Here’s the full button:

    https://cs11.salesforce.com/a2v/e?CF00NF0000008yAJA={!rstk__rtrouthdr__c.Name}&CF00NF0000008yAJA__lkid={!rstk__rtrouthdr__c.Id}&CF000NF0000008yBTy__lkid=a2tZ0000000HKzN&CF000NF0000008yBTy=MFG&Name={!rstk__rtrouthdr__c.Name}&retURL={!rstk__rtrouthdr__c.Id}

    Note: these are fields built by a managed package, I don’t know if possibly there is some problem there, but seems unlikely. I’m using a standard page layout. I can pre-populate regular (non lookup ) fields without an issue.

    page layout for reference:
    http://i.imgur.com/pRToH6u.png

  4. Hi,

    I am trying same thing to create new task so fields get populated from previous tasks. however not sure why it’s not working.
    also the layout has turned out to be a bit odd, showing a webpage within a webpage.

    1. Here is one from my Dev Org that I made a while back. its on the account object as you can probably tell. The ID’s for the fields aren’t immediately obvious. What I had to do was right click on the field and click “Inspect Element” on chrome. I could find the ID of the field from here. The below, tsk6 currently populated the comment box with ben! Hope this helps.

      /00T/e?what_id={!Account.Id}&retURL=%2F{!Account.Id}&tsk6=ben

  5. I am trying to create a new button to create an opportunity from another opportunity, like a child. The child will have many of the same fields and I would like the new opportunity name to be the original opportunity’s name appended with “2”. I can’t find the field ID for Opportunity Name? Do standard fields have a different way of finding the field ID?

    1. Standard fields are a bit tricky. To get the ID of the fields its best to use chrome. right click on the field in salesforce and click inspect element. This will show you the field name in the code. The Id you need though is opp3 so &opp3=BensOpp

      Hope this helps!

  6. REALLY weird situation. We have a validation rule on a picklist field (Substatus__c) that ensures Status cannot be Open if Substatus is not blank. I created a button to create a new case. Substatus is not used on this record type, so is not on the page layout. When I trigger the button and save the case (Status = Open substatus is not on page layout so therefore is blank), it fires the validation rule. If I PUT the substatus field on the page layout, and perform same situation, it WILL save solely because the field is visible ON the page layout…

    I tried forcing the field to be blank, but it still triggers the val rule. Any way to force the field to be blank in the button, or know why this URL hack is firing the validation rule?

  7. I am trying to go two levels deep with my URL hack can this be done? So I have a Quote object, that is created from an Oppty, and that Oppty is created from an Account record. I would like to capture a field value from the Acct record and pass it to the Quote record, can this be done? I can get Oppty field values (Opportunity.Name) passed to my Quote no problem, but I want a value from Account record to go to the Quote record, help please. Thanks.

    1. Hi Rey,

      I don’t think you could do this just with a button. However, you could quite easily use a formula field on the Opportunity to grab account data then pass this into the Quote, does that make sense?

      1. Hi that does make sense, but trying to avoid creating another field on the Oppty object which I would have to do based on your comment correct? We already have so many fields on our Oppty object, so we are trying to watch that now. Any other suggestions?

        The field that resides on the Acct object I want is called Acct Mgr. I want to pass Acct Mgr to my Quote object. Do you think I could just create the new field (Account Manager) on my Quote object and then use a Trigger/Field Update to populate the new field on the Quote object after the Quote object is saved?

    1. Hi Fraidy,

      Standard fields are a bit more tricky. If you use Chrome as a browser, go to the field in Salesforce and right click on it, select inspect element. This will show you the “code” for the field. Depending on what field it is it may look something like this for opportunities “opp3”. I feel another post coming on this!

      Hope this helps,

      Ben

  8. Ben,
    I have some pretty advanced URL Hacks going but run into an “unterminated string literal” javascript error when attempting to pass a Text Area field value in a Service Cloud Console hack. I suspect it has to do with line breaks in the Text Area field breaking the URL. Any tricks for passing the Text Area fields across a URL Hack?

  9. Ben

    Great tutorial!

    I’m trying to populate the Asset lookup field to create an RMA Record that is a junction object between the Asset and Case. Asset Name ( {!Case.Asset} ) is not unique, so I get multiple matches in my RMA Hack URL Button.

    Any suggestions to prevent specify the name of the Asset Record Identified in the {!Case.AssetId}?

    Here is my URL Button code:

    /a03/e?
    CF00Nq0000000oXen={!Case.CaseNumber}&
    CF00Nq0000000oXen_lkid={!Case.Id}&
    CF00Nq0000000oXes.lkid={!Case.AssetId}&
    CF00Nq0000000oXes={!Case.Asset}&
    retURL={!Case.Id}

    Thank you

    Curt

    1. Same issue here. I’ve been doing these button hacks for several years and this has always been an issue. Salesforce won’t comment on the issue because button hacks are not supported. I’m hoping some genius out there has figured it out.

  10. Hi Ben,

    Please I am trying to create a button on a custom object where when the user clicks on the button on a record type A, It opens Record Type B in another page without changing the record type of the record itself..Please help. Thanks

    1. Hi Ayo,

      This will probably be because it will automatically go to the default record type. I think you will need to put a parameter in your URL hack which looks like this &RecordType= and then put the record type ID that you wish it to be.

      Hope that helps,

      Ben

  11. I have a rare situation. Custom object has two lookup fields and both have same Id of 15 characters: 00N23000000FrIh and 00N23000000FrIH. So only difference in their Ids is the last alphabet. One has small h and other has capital H. Both fields are present in the pagelayout. Now the issue: When I am trying to populate value in one field, it is actually being coming in the other field. URL and HTML both are case insensitive languages. Can anyone suggest some solution.

  12. Hi Ben – many thanks for valid, active and useful site.
    If I may:
    Using custom URL button – I want to set the cancel/return url AFTER the recordtype was selected:
    /setup/ui/recordtypeselect.jsp?ent=Case
    &save_new_url=/500/e
    &cancelURL=/{!Presales_Activity__c.Id}
    &retURL=/{!Presales_Activity__c.Id}

    Regards,

  13. Hello! Would you have any suggestions for how this might look for replicating the Add to Campaign standard button on a Contact layout? Looking to mimic the functionality but set the default to ‘All Campaigns’ and add initial search criteria. Cheers.

  14. Hi,

    Is URL Hacking is the best way to customize the button in Salesforce. I’m new to Salesforce. I dont know whether it’s the best way or not

  15. Hi Ben,
    Great site and always very useful. I have a URL hack button on an Opp to clone a record and pre-pop certain fields. Can i include something in the URL to update a custom check box field on the record being cloned, rather than it goes straight to the new, cloned record? If i can solve this i’ll be the happiest Admin on the planet.

  16. Hi Ben,

    This tutorial has been great! I have created a custom oppty button that populates the description field. My company wants to the button to enter questions into the description to prompt answers from field. Any idea if we can “return” within the description box to get the questions on separate lines in the box. Can this be done within the custom button?

  17. Ben, The Man, the Legend!
    Can you speak to the changes in URL hacking with the recent Salesforce platform upgrade to lightning? I’ve read in a few posts that it will make hacking urls in these ways very limited. That’s a huge bummer since I’m just getting the hang of it! Also +1 superhero status if you (or anyone) has a “save and new” hack, where I can tranfer the same values from my original “new” click into my save and new button click. Thanks.

    1. Hey Josh,

      My reputation precedes me!

      Unfortunately what you’ve heard is true, it will no longer work properly with the way that Lightning is designed. This was always kind of expected seeing as URL “Hacks” were never a supported method of doing something. However, from what I’ve heard, depending on the solution you have designed Quick Actions might be able to solve a lot of your problems. They might not be able to replicate them 100%, but you can use a combination of Quick Actions and Process builder to hopefully create a similar solution.

      Hope this helps!

      Ben

  18. So, what is the real risk of developing a bunch of these buttons — and having them all crash because your ORG has been moved to a different server — or whatever event could cause such a thing to happen?

    BFey

    1. Hi Brian, these “hacks” are of course not supported by Salesforce but have been around for a number of years and are generally accepted as a valid feature. Moving to another server would not affect this as they append parameters after the server part of the URL. Thanks Ben

  19. Hi Ben,

    I’m assuming this isn’t possible but I figured I’d inquire anyway….
    I would like to customize the button on the quote layout when viewing a newly generated PDF (It’s a pop-up that shows over the actual layout of the quote to let you preview the PDF before sending.)
    Do you think it would be possible to customize that button to prepopulate the “Send to” email field?

  20. Hi Ben,
    This Tutorial has been great. Is it possible to auto-populate fields to a Custom VF page, how should i specify the link in the button. (I Want to Auto-populate fields from Opportunity to a Custom VF page with Standard Controller as Quote)

    Thanks,
    Onesh

  21. Hey Ben,

    Can you please tell me how can i pass value in standard field Using URL (I use custom button) ??

    Thanks
    -Nihar

    1. If you want to find out the Id of ‘Account Name’ standard field from Account object (using chrome browser)
      – Click on new Account
      – Right click and select ‘View page source’
      – Search with string ‘>Accoutn Name<' you can find line something similar to
      *Account Name
      here acc2 is the id

  22. Hi Ben,
    I have a custom object with 2 different record types. When I click the New OBJECT button, I want to still be able to select the record type instead of it just using the default record type. The fields I then want to pre-populate will be the same on both record types but I don’t know how to get to this recordselect screen and then pass over the value.
    Any help would be greatly appreciated!
    Thanks,

    Emma

  23. Harshit Agrawal

    Reply

    Hi Ben,

    How can we populate the value to hidden field on standard edit page from custom button? I want to populate the value to a field which is not added on page layout. When I click the custom button then it redirects to Contact standard edit page in which I need to populate the dynamic value coming from custom button to a field which should not be displayed to users so it is not added on page layout. I want to use that field value in Contact Trigger.

    Is there a way to do this? I know, VF page is an option but don’t want to create VF page for this single requirement.

  24. We have a NEW button for a custom Object that’s opens up from the Contact tab with a couple pre-populated fields. The pre-populating is working great but the standard page for the new custom object record is opening inside the Contact tab where it was called from, so the users sees 2 rows of tabs. Is there a setting to make the New record page open without being inside the Contact page?

      1. Hi Ben,

        I created a button that created new custom object record from Contact record. This URL Button works perfectly on our Sandbox instance. However when I use it in our Production instance it does not work.
        I did make sure to change the field code and object code as indicated in Production.
        /a23/e?CF00NK0000001uGhj={!Account.Name}&CF00NK0000001uGhj_lkid={!Account.Id}&CF00NK0000001uGfs={!Contact.Contact_Full_Name__c}&
        CF00NK0000001uGfs_lkid={!Contact.Id}&
        00NK0000001uHXt=”Potential”
        Could you please advise me how could this be solved?

  25. Hey Ben,
    Please disregard my question from today about having the new record page visible within the Contacts tab, as this was just a simple setting on the List button setup.

    Thx’s Greg

  26. How about a standard field id on a custom object? For instance, the field that is required to name the detail record of a master detail relationship. I have a choice of a text or number in the setup, here I have chosen text but would like it prepopulated with data from the Master and workflow to update after saved based on picklist values chosen on the the detail. I have looked through the code and cannot find a solution.

  27. Hi! This tutorial was awesome!! Can you give me some advice as to how I can auto populate multiple fields in just one click of a button? I wanted to auto populate 3 fields when creating a task. So far I am only able to auto populate one field. I tried using the && but it did not work. I’m not a developer tho, so maybe you have something that can solve this?

    Thank you in advance!!

  28. Hi, Thank you for sharing this useful article!
    I am trying to populate standard lookup fields. Where can I find the IDs for this? And what will happen if the Id is not correct?

  29. Hi Ben,
    Thank you for this great tutorial.
    I followed the logic and created this button when i create a custom object record from Contact.
    /a23/e?CF00NK0000001uGhj={!Account.Name}&CF00NK0000001uGhj_lkid={!Account.Id}&CF00NK0000001uGfs={!Contact.Contact_Full_Name__c}&
    CF00NK0000001uGfs_lkid={!Contact.Id}&
    00NK0000001uHXt=”Potential”
    This works perfectly on my Sandbox but when I set it on my Production environment it does not work. I made sure to change the field unique code and also the object code is different in Production namely /a26/
    Could you please advise me what am I doing wrong or missing out here?

  30. Hi Ben,
    I am not sure if my previous post was received therefore I send another one.
    I created this URL hack on a button that creates new custom record from Contact record:
    /a23/e?CF00NK0000001uGhj={!Account.Name}&CF00NK0000001uGhj_lkid={!Account.Id}&CF00NK0000001uGfs={!Contact.Contact_Full_Name__c}&
    CF00NK0000001uGfs_lkid={!Contact.Id}&
    00NK0000001uHXt=”Potential”

    However, when I use it on Production it does not work
    /a26/e?CF00Nb000000A16YB={!Account.Name}&CF00Nb000000A16YB_lkid={!Account.Id}&CF00Nb000000A16YA={!Contact.Contact_Full_Name__c}&
    CF00Nb000000A16YA_lkid={!Contact.Id}&
    00Nb000000A16Yh=”Potential”

    Could you please advise how should solve this?

  31. Hi Ben,
    I could able to create such button in salesforce classic but don’t see it in salesforce1 app… can you suggest something for salesforce1 app ? how shall I create a custom button for create_new_event from a account which prepopulates some account fields on event new page ?
    I am trying to do via creating a publisher action as visualforce page .. but its not working ! Please guide me through !
    Thanks,
    Namita

  32. Hi Ben how are you?
    I’m trying to create a clone button using this code:
    window.open(‘https://cs2.salesforce.com/{!Account.Id}/e?clone=1&00N37000005Q4b4=Inativo&00N37000005abi6=Null&00N37000005Q4ad=’+cnpj+’&save=1’);

    I want that open a windown, with some fields changed, and already saved, but the windown that is opening is not saved, and an error appear saing that:
    “The page you submitted is invalid for your session. Click Save again to confirm your change.”

    Could you help me?
    Thanks a lot.
    Fernanda Ribeiro

  33. Hi Ben,

    I was just going through the steps to create the hack button and got stopped at the first step. I created the button inside my Sandbox, for my Opportunity object. chose the same settings you chose, went to the related list and couldn’t see the Custom Buttons section. This means I cannot choose the button I just created. What am I missing?

    Thanks

  34. Hi Ben,

    What if we don’t want to create a new custom button, but rather hide a Standard Button? I would love to get rid of the “New” button on the Account Tab and the “New Account” button on Account List Views. We are trying to force users to only create new accounts via Lead Conversion. Any ideas?

  35. Pingback: Salesforce Visualforce Code Generator - dieffrei.com

Add Comment