Salesforce URL Hacking to Prepopulate Fields on a Standard Page Layout

Edit 5/15/2013:
Wow, over 200 responses, thanks everyone! I’ll continue to leave this page and all of its replies on one page so it’s easy to search. Just a note: if you’re planning to ask a question, that’s perfectly fine, but please adhere to these guidelines:

  1. Please read the existing questions and answers, your question might be in there!
  2. Please provide sufficient information, including:
    1. What are you trying to accomplish
    2. What are the contents of your URL (pre-merged) e.g. /a0B/e?CF00NA0000005JzZX={!ObjectMaster__c.Name}
    3. What is the resulting URL generated by your button (post-merged) e.g. /a0B/e?CF00NA0000005JzZX=Billy+Bob
  3. Once you’ve posted, if you would like an expedited response, please feel free to email me.

Thanks! Now onto the content…

By default, when you create a child object from a related list, only the parent lookup field is defaulted and filled in.

hacking urls is fun

hacking urls is fun

Often times it is extremely useful to have some of these other fields filled in. Unfortunately, this is not out of the box — there is no way to configure editable fields on a child object which are defaulted to the parent’s value. Fortunately, it’s fairly straightforward to fulfill this requirement with a little URL hacking!

If you look at the resulting URL of the “New ObjectDetail” button click, it is:

https://na10.salesforce.com/a0B/e?CF00NA0000005JzZX=Master1&CF00NA0000005JzZX_lkid=a0AA0000002CtHk&retURL=/a0AA0000002CtHk

Categorized:

https://{org}/{object prepend}/e?{some ID field}={some value}&{some ID field}_lkid={some other ID field}&retURL=/{some third ID field}

Explained:

  • org: e.g. na1.salesforce.com
  • object prepend: e.g. 003 for contact. This is the first 3 characters of an object, and the most reliable way to get this information is by API command:
    Schema.getGlobalDescribe().get('Contact').getDescribe().getKeyPrefix()
  • some ID field: e.g. CF00…. This corresponds to the ID of the field that you want to be prepopulated. This will always be the text that is displayed in the box.
  • {some ID field}_lkid: e.g. CF00…_lkid. If the field in question is a lookup or master-detail, then this field should be set to the resulting record ID {some other ID field}. Note that in this case, the actual non _lkid field is irrelevant, and not consulted.
  • some third ID field: e.g. 003… This is the URL that the user is redirected to upon successful save of the record.

The theory is that if we can properly guess the name and set these fields to a certain value for a custom button that looks like “New ObjectDetail”, for instance, we can have a robust solution.

Part 1: Getting the IDs Required

The best way that I’ve found to get the ID of the field that you want populated is by navigating to the field in setup. For example, if I want to prepopulate ObjectDetail__c.TextField__c, I would go to Setup => Create => Objects => ObjectDetail => TextField, which takes me to to the URL

https://{org}/00NF00000082xeJ?setupid=CustomObjects

00NF00000082xeJ is the ID of the TextField__c field. Sure enough, if I append &00NF00000082xeJ=Test+Text to the URL above, making the full URL

https://na10.salesforce.com/a0B/e?CF00NA0000005JzZX=Master1&CF00NA0000005JzZX_lkid=a0AA0000002CtHk&retURL=/a0AA0000002CtHk&00NF00000082xeJ=Test+Text

I see the following:

hacking urls is fun

Success! Iterate over each field required and set accordingly. The only important thing to remember is that if a field is a custom lookup field, we need to prepend the ID with CF. Also, note that text values must be EncodingUtil.urlEncode()‘d or URLENCODEd, otherwise a simple string like “Tom & Jerry” will not pass along correctly. Sometimes this is done for you, depending on the method you use.

Part 2: Overriding the Standard New Button

Now that you know the URL, you simply have to create a button that forwards you to that URL. In my opinion, the most robust solution would be a Visualforce Page button, because that enables a lot of flexibility for customization, translation logic and error checking. However, for this proof of concept, I’m just going to show you how to create a very simple button that will forward you to the correct URL.

hacking urls is fun

The URL I put in is:

/a0B/e?CF00NA0000005JzZX={!ObjectMaster__c.Name}&CF00NA0000005JzZX_lkid={!ObjectMaster__c.Id}&00NF00000082xeJ={!ObjectMaster__c.TextField__c}&retURL=/{!ObjectMaster__c.Id}

Which simply pulls in the Name, ID and TextField from the parent.

I then go to the ObjectMaster page layout, click the wrench next to the ObjectDetail related list, and remove the New button and add the freshly created “New ObjectDetail” button:

hacking urls is fun

Go back to the ObjectMaster record and confirm that it works.

hacking urls is fun

hacking urls is fun

Part 3: Caveats and Areas for Improvement

There are a few areas of consideration for this approach:

  • If you do not need the field on the child to be editable, use a formula field instead.
  • If you need the field to be defaulted but not to any particular value from the parent, use the standard default value when possible.
  • Avoid hardcoding IDs whenever possible. In particular, the ID of fields will likely change if this button is to be deployed to another environment. Unfortunately with this approach, the ID has to be hardcoded somewhere (I think, please correct me if there is a way to get at it programmatically). If a value has to be hardcoded, it should be done in a custom setting, and can easily be accessed via a VF page button.
This entry was tagged , . Bookmark the permalink.

324 Responses to Salesforce URL Hacking to Prepopulate Fields on a Standard Page Layout

  1. Andy Crossman says:

    Brilliant article – really helpful & have used in many places already.
    Question I have is – I am trying to pre-populate some of the standard fields when creating a new custom object from a custom button.
    The custom fields are working fine, but I can’t seem to find how to populate the Name and CurrencyIsoCode fields.
    How do I find out what the IDs of these fields? The only ID that shows when going in to edit them is the object ID …
    Any help most welcome …
    Many thanks!

  2. Alex Kasperavicius says:

    @Andy

    These are just simple names:

    CurrencyIsoCode={!Opportunity.CurrencyIsoCode}
    Name={!Opportunity.Name}

    If it’s a custom object Name will be a unique ID. Just inspect the HTML and you will discover the unique ID for each field.

    Now, I have read that there is a way to save and CLOSE a record using this technique, but still digging. If anyone knows, please post.

    • Billy Silva says:

      You can add “&save=x” at the end of the url to automatically save and close the action

  3. Yervand E. says:

    Great article. Everything worked great, except the retURL is not working for me. After updating, it stays in the related object detail page.

  4. Ingo says:

    @Andy

    for standard fields, use their API name. For name and currency this would be “Name” and “CurrencyIsoCode”:

    https://{org}/{object prepend}/e?Name={some value}&CurrencyIsoCode=EUR={some value}&

  5. Michael L says:

    Does anyone knows how I can get what fields are being display from the field set in the code behind (apex)?

  6. Priya says:

    Really Thank you very much for this post. It is very helpful for me…..

  7. Jin Daikoku says:

    Does this work with lookup fields? I’m trying to populate the contact and synced quote… :(

  8. Vikram Singh says:

    Great article………..
    But facing problem when we are fetching the master object’s lookup feild value.
    Thanks

  9. Lokendra says:

    I want to auto-populate some of the standard fields of Standard child object from the standard fields of standard Parent Object.
    Problem: Not able to find the Ids of the Standard field of standard child object
    When i am analyzing the HTML code for the edit page of the standard child object, not able to find the ID’s for the child’s standard fields (they are using the API name for the standard fields)………
    Also when i am using the API name for standard fields of the child standard object to view(In URL), then it is saying the URL you are looking for doesn’t exist……….
    Any help is much appreciated.

  10. Søren Krabbe says:

    Has anybody been able to do this for multi select picklists? If I provide a single value it work great. But I cannot figure out how to provide multiple values.
    Separation by “,” or “;” does not seem to be the answer.

    Thanks

    • Søren Krabbe says:

      Out of frustration, I tried:
      …/e?…&myMultiselect=Value1&myMultiselect=Value2

      And it worked!!

      • Ray Dehler says:

        Interesting — are you saying that you set the same var twice on the query string and it pulled in both?

  11. sagar patil says:

    This is great article , helped me a lot in my implementation.
    There is another easier way to find field ID using fireBug add-on(is available for most of the browser).
    With the help of Inspect tool of firebug add-on when i checked a input text field and which i copied and pasted below, salesforce puts actual ID of the Field into id & name attribute of element.
    i.e id=”00N90000000NsuP”
    name=”00N90000000NsuP”

  12. warren cowan says:

    Nice post…been looking for a way to do this.

    Wondered if you’d care to have a go at url hacking the new dashboard filters in winter 12. now that would be huge. You could create filtered dashboards for your accounts, and then embed the values into formulas on their account record. Care to give it a go?

  13. Steven says:

    Does this still work? I’m trying to pass parameters through from the New button on the Opportunity related list on the Account page. Customized the button but although the parameters are visible in the URL, the fields are still empty.
    Button looks like (just a simple test):
    /006/e?Name={!Account.Name}

    URL comes out as
    https://na1.salesforce.com/006/e?Name=company+name

    but the name field does not display any data. I can’t get it to work with any other fields either.

    Thanks

    • Steven says:

      OK had a little success, to point Opportunity.AccountId to the correct account, instead of referencing by api name like Name, I had to use accId={!AccountId}. Don’t know where accId comes from, I just found it on Google, tried it and it worked. I’m trying to point a custom lookup field to the account owner but having no success. this doesn’t work at all:
      &CF00N30000005vzH4_lkid={!Account.OwnerId}

      tried without _lkid (so just &CF00N30000005vzH4={!Account.OwnerId}) and I limited success, in that the lookup field is populated, quite literally, with the ownerId, which is obviously not what I’m looking for. Tried going a step further by calling Account.Owner.Name but it wont let me. Presumably you can’t traverse that far down the tree. Any suggestions?

      • Steven says:

        Solved it. The _lkid param WAS Working, it was populating the value in the background but not displaying it in the field. To do that you must pass CFXXXXXXXXXXXXXX=stringliteral where stringliteral is the string name you want to display in the text box

        • Ray Dehler says:

          Yes, that’s correct Steven.

          • Siva says:

            Hi Steven, Ray,
            I am trying to clone the task record and successful with passing ownerid to the new record, but unable to show the name of the owner (Assigned To) in the task create page. Can you please elaborate how to achieve this?

          • Siva says:

            Thanks. Able to achieve this by
            1) Using a trigger to populate owner name to a custom field in task
            2) Passing the custom field value to owner name during clone and ownerid is passed from the ownerid value

  14. Chris says:

    Hi Ray,

    This is a super helpful post, thanks for sharing it with the world! One question, do you know how to populate a user look up field via a url? I added a formula field to our contact page layout that when clicked opens an edit screen for an opportunity and prepopulates some of the oppty fields. Everything is working great…except a field that is a look up to a user. Cant get that to work using the same logic as how you set, say an account look up. My hypothesis is that it is because our org has customer portal, so our user fields, when edited through the UI, have a “user type” field that includes: internal user, customer portal user. But I can’t find any info on this, and Salesforce support has been unhelpful.

    Here is one version of the URL I am using, the offending field is “SDR Owner Look Up”. You can ignore the SDR_owner__c field, that is a text field and is being set properly. Any ideas on how to accomplish this?

    “/006/e?opp4=” & Account.Name
    & “&opp4_lkid=” & Account.Id
    & “&conid=” & Id
    & “&opp10=Develop Joint Account Development Plan”
    & “&opp11=Target – Active Development”
    & “&opp6=” & TEXT(LeadSource)
    & “&opp9=” & TEXT(MONTH(TODAY()+180)) &”/”& TEXT(DAY(TODAY()+180)) &”/”& TEXT(YEAR(TODAY()+180))
    & “&00N50000001ODYc=” & Lead_Source_Comments__c
    & “&00N50000002OaYz=” & TEXT(Buying_Behavior__c)
    & “&00N50000002OaYp=” & TEXT(Lead_Category__c)
    & “&00N50000002P0MK=” & TEXT(Sales_Lead_Type__c)
    & “&00N50000001fTVE=” & TEXT(Account.CRM_System__c)
    & “&00N50000002OpkH_lkoid=” & SDR_Owner_Look_Up__r.FirstName &” ” & SDR_Owner_Look_Up__r.LastName
    & “&00N50000002OpkH_lkid=” & SDR_Owner_Look_Up__r.Id
    & “&00N50000001vhFu=” & TEXT(SDR_Owner__c)

    Thanks!

    -Chris

    • Ray Dehler says:

      Chris-

      I think what you want is instead of
      & “&00N50000002OpkH_lkoid=” & SDR_Owner_Look_Up__r.FirstName &” ” & SDR_Owner_Look_Up__r.LastName
      & “&00N50000002OpkH_lkid=” & SDR_Owner_Look_Up__r.Id
      is
      & “&00N50000002OpkH=” & SDR_Owner_Look_Up__r.FirstName &” ” & SDR_Owner_Look_Up__r.LastName
      & “&00N50000002OpkH_lkid=” & SDR_Owner_Look_Up__r.Id

      You may have to encode the name as well, in case it has a “&” character in it, for instance.

      • Chris says:

        Yes, unfortunately that doesn’t work either…its a tricky one! Any other ideas? I have tried every possible combination, but to no avail.

        • Ray Dehler says:

          When the field is a lookup, you have to prepend “CF” to the field ID. In other words
          00N50000002OpkH_lkid=” & SDR_Owner_Look_Up__r.Id
          should actually be
          CF00N50000002OpkH_lkid=” & SDR_Owner_Look_Up__r.Id

          Try that?

          • Carol says:

            Hi Ray,

            Thanks for your responses! I’m working with Chris and prepended CF to the field ID, but that didn’t work either. I’m so stumped! Do you have any other suggestions?

            Thanks,
            Carol

          • Ray Dehler says:

            Carol — sent you an email.

          • Chris says:

            Carol got it to work! Thanks Ray, you are a gentleman and a scholar!!

          • Ray Dehler says:

            Hey great news!

          • KR says:

            Hi Ray,

            I am trying to populate a look up value on the custome field. But I see that all other fields (including look ups) are being populated except this Property__c field.

            We are creating page A and on click of save on page A(propery), the java script should navigate us to page B (property Child obj) where it has a look up on Page A. So on Page B the property__c field is not populated.

            var editURL = ‘/a04/e?CF00NC0000005armW={!URLENCODE(Account.Name)}&CF00NC0000005armW_lkid={!Account.Id}&CF00NC0000005arma={!URLENCODE(Property__c.Name)}&CF00NC0000005arma_lkid={!Property__c.Id}&retURL=/{!Account.Id}';

            var urlSpecialCh=’/a08/e?CF00NC0000005armW={!URLENCODE(Account.Name)}&CF00NC0000005armW_lkid={!Account.Id}&retURL=%2F{!Account.Id}&saveURL=’+editURL;

            window.location.href = urlSpecialCh;

            Please let me know where I am doing wrong. Thanks for all your help!!

  15. Pingback: Thinking Like Salesforce « JodieM.com.au

  16. mayank says:

    Hello,
    “unfortunately with this approach, the ID has to be hardcoded somewhere (I think, please correct me if there is a way to get at it programmatically). If a value has to be hardcoded, it should be done in a custom setting, and can easily be accessed via a VF page button.”

    This is the problem I am facing , I just hardcoded the ID’s and need to deploy in other environment.What do you mean by “it should be done in a custom setting” please explain with example as its very important

    • Ray Dehler says:

      Mayank-

      I sent you an email about this, but I thought I’d post it here as well.

      Yes, I was hoping this would come up. Here is what I meant. I’m assuming the field you want has API name Account.Custom_Field__c.

      Create a hierarchy custom setting, called URL_Parameters__c for instance.
      Create a custom field on this custom setting called Account_Custom_Field__c, type Text (18).
      Manage the custom setting, add the org default and save your field ID here.

      In a custom button, access this field via:
      {!$Setup.URL_Parameters__c.Account_Custom_Field__c}

      In a VF page, via:
      public static URL_Parameters__c parameters = URL_Parameters__c.getOrgDefaults();
      public static String fieldId = parameters.Account_Custom_Field__c;

      Does that help get you started?

      • Bryan Roller says:

        I was looking at doing this as we create these items in a sandbox and then move them to production and always have to go in and change the SFIDs after the move. Would we still have to change the SFID in the custom setting in the instance we just moved to using this process? So, effectively would we still do the same thing, i.e. update the SFIDs, but just in a different location (custom settings vs the button code)?

        • Ray Dehler says:

          Hi Brian Roller — yes, you would still have to update the value post-move. If it’s button code it’s not so bad, but if it’s in apex or visualforce, it’s a bit more heinous to deploy to a production instance, which is why I suggested the custom setting. I’ve seen it done both ways in practice.

          • Sebas Canseco says:

            Ray, so I’m thinking about the custom setting you propose as a Global Constant analogy? Meaning, it’s easier to update the value of a global constant than updating the value across the entire code, correct?

            I’m very newbie at SF, so would you mind to explain where to find the “Create a hierarchy custom setting”

  17. Sylvain says:

    Thanks for this post Ray; it allowed me set up a custom button (“Create Visit Report”) on the standard event object that opens a new custom object (“Visit_Report__c”) and all fields are wonderfully prepopulated. Our Sales guys are very happy about this.

    Now I was wondering if it’s possible to add some code that copies attached files from my event thru to my custom object?

    This is the code of the pop up where you upload the attachment:
    https://emea.salesforce.com/p/attach/ActivityAttach?relatedListId=00U2000000HwJEc_RelatedActivityAttachmentList&retURL=%2F00U2000000HwJEc%2Fe%3FretURL%3D%252F00U2000000HwJEc&pid=00U2000000HwJEc&type=00U

    Button Code:
    /a0M/e?retURL={!Event.What}&CF00N20000002tGRM={!Account.Name}&CF00N20000002tGRM_lkid={!Account.Id}&CF00N20000002tJAe={!Contact.Name}&
    CF00N20000002tJAe_lkid={Contact.Id}&00N20000002tLH8={!Event.Location}&Name={!Event.Subject}&00N20000002tJEg={!Event.StartDateTime}&00N20000002tJF0=!Event.EndDateTime}&00N20000002tJAo={!Event.Description}

    Any ideas appreciated!

    Sylvain

    • Ray Dehler says:

      Sylvain-

      I don’t believe that this can be accomplished with URL hacking.

      This might be able to be accomplished with a simple Visualforce page to be included on the page layout which would load the Event’s attachments, having only 1 attachment rather than making a copy of it, and effectively having 2 which could become out of sync.

      This could be accomplished pretty easily with a trigger as well, but there would have to be some additional considerations.

      Cheers,
      Ray

  18. Alexis Kasperavicius says:

    Ray —

    Thanks again for this page. One quick question:

    Are you aware of any way to populate AND SAVE a record via URL hacking – all in one stroke? What I want to do is create a populated record and save it – automatically – without bothering the user, and send them to the return URL.

    I seem to remember reading somewhere that this was possible, but with everything I’ve tried the filled out page just sits there waiting for the user to press save. I suppose I could make some script to do it or … ? Any ideas?

    Thanks,

    AK

    • Ray Dehler says:

      Alexis-

      I’ve never seen this. This could be accomplished by wrapping with a Visualforce page, but you’re saying you saw this without that I assume. I’d be interested in hearing more about this if you find it again.

      Thanks!

  19. Mir Khan says:

    Hi Ray, nice post. Although, I had one question, my custom object has a lot of required fields (ex: Account Business Name, Shipping Address etc) that are prepopulated from the standard Account object using the custom link. However, some of the fields that I have required in my custom object arent really required on the Account, so if those fields arent populated on the Account, as soon as I click the custom button to prepopulate data to the custom object, all of the required fields that are not populated complain that a value is required even though I havent hit save on the custom object.
    I dont know if my question made sense, but its mainly around having required fields that are not pre-populated since the source object doesnt have data to prepopulate.
    Was wondering if you encountered a situation like this and would love to know how you approaced with a solution.

    • Ray Dehler says:

      Mir Khan-

      Yes, your question makes sense. The way to accomplish this would be to check if the value is set before passing it on the url parameter. For example, instead of this in your URL:
      00NF00000082xeJ={!ObjectMaster__c.TextField__c}
      Do this:
      {!IF(NOT(ISBLANK(ObjectMaster__c.TextField__c)), “00NF00000082xeJ={!ObjectMaster__c.TextField__c}”, “”)}

      Ray

      • Mir Khan says:

        Wow Ray!! Thanks for the prompt response.
        However, would I be able to check for nulls within the URL or do I have to do it outside?
        Ex: https://xxx.salesforce.com/xxx/e?{!IF(NOT(ISBLANK(ObjectMaster__c.TextField__c)), “ooNxxxxxxxxx={!ObjectMaster__c.TextField__c}”,””)}&the rest of the URL
        is complaining of a syntax error

  20. Mir Khan says:

    I take my words back… its working. The problem was with the quotes, I had single ones instead of the double. Ray my friend, you are a genius!! Thanks again for the fantastic tip.

  21. Mir Khan says:

    May be I spoke too soon, the null part works, now the issue is around the Master object having values and those values are not being passed over to the custom object.

    • Ray Dehler says:

      Mir Khan-

      I’ll send you an email about this so we can get it resolved without flooding comments, and we’ll post a resolution comment when it’s fixed.`

      • Karin says:

        Hi Ray,
        Did you find a solution for this problem of other fields not being populated?
        I’m having the same issue.
        Thanks,
        Karin.

      • Karin says:

        Hi Ray,
        Trying again:
        Did you find a solution for this problem of other fields not being populated when using an “If” statement?
        I’m having the same issue.
        Thanks,
        Karin.

  22. Jenni says:

    Great post. Is there any way to code a custom button to create more than one record? I need to create 8 seperate instances for a record and wasn’t sure if I would need to do a visual force page or if I could simply do it with a button. Right now I’m able to create one record and save. /a0P/e?CF00N40000002RgQU={!Jobs__c.Name}
    &CF00N40000002RgQU_lkid={!Jobs__c.Id}
    &00N40000002Rfv2=Breakfast Area
    &Name=Breakfast Area
    &save=1
    &retURL={!Jobs__c.Id}

    For each record everything is identical except &00N40000002Rfv2=Breakfast Area &Name=Breakfast Area, which would simply be different text ie) Lobby

  23. Jenni says:

    Thanks Ray, Apex is above my comfort zone so I’ll need to get my programmers involved. Thanks again.

  24. W. MacKenzie says:

    I have a detail record that uses a lookup field which is not intuitive for the end cust to use easily to fill the field using SF’s std lookup mechanism. So, I wrote a custom VF page that does the lookup using dynamic SOQL.

    Now, I need to “wire” the “stock” salesforce detail page lookup field to my custom VF page. Would using the URL hacking approach here do the trick? ie: a custom URL next to the lookup field which would invoke my custom VF page passing the Name and ID of the lookup field. Then once the user selects it do I just then assign the ID of the record selected to that ID?

    Any suggestions here would be most welcome!

    thx.

    • Ray Dehler says:

      W. MacKenzie-

      I’ve never seen this done, but that doesn’t mean it can’t be accomplished. That’s not really what this post is about, however.

      Ray

  25. Pingback: salesforce development | Pearltrees

  26. Hanu says:

    Hi Ray,

    Can you please help out with prepoulating Product column for create new case URL. Tried CFProduct_lkid, CFProductid__lkid, ProductID_lkid, and Product_lkid, but no luck.

    Looking at the Firebug, the id shows as “Product”. Acccount and other custom field works fine by using the id shown by the Firebug.

    Thanks again for the great post
    -Hanu

    • Ray Dehler says:

      Hanu-

      Case.Product is a custom field, right? Isn’t there a custom field ID you could use?

  27. William says:

    Great article. I’ve done this with my custom objects but am having a tough time with creating a custom new task button that passes another user into the assigned to lookup. I got it to pass the correct ID but the lookup still populates me as the assigned to.

    Here is the code… The button is a custom image. I’ve got it to work with other activities including creating a standard task. But when I pass the ID of another user in it, it ignores that and puts me in there.

    HYPERLINK(‘/00T/e?who_id=’ & $User.DelegatedUserID__c & ‘&what_id=’ & Id & ‘&retURL=’ & Id, IMAGE(‘/servlet/servlet.FileDownload?file=01540000000jgyw’, ‘Create Task’))

    • Ray Dehler says:

      William-

      who_id is the “Name” field on the Task, which can only be a Lead or Contact. Surely you want the “tsk1″ field, which corresponds to the “Assigned To” field. The difficulty becomes how to get the User’s Name that corresponds to $User.DelegatedUserID__c.

      This more closely matches what you want:
      HYPERLINK(‘/00T/e?tsk1=name_goes_here&tsk1_lkid=’ & $User.DelegatedUserID__c & ‘&what_id=’ & Id & ‘&retURL=’ & Id, IMAGE(‘/servlet/servlet.FileDownload?file=01540000000jgyw’, ‘Create Task’))

      You’ll have to get creative with the name_goes_here part, there are a few ways to get the actual name. Note that this value is purely cosmetic, and all you really need is the lkid portion to have it correctly assign the task to that user.

  28. William says:

    Hi Ray,
    Thank you for the reply. I’ve been trying to figure this out all day but am getting stuck in one area. When I pass the tsk1_lkid value over, it shows up in the URL as the field name, it’s not reading the field value. See the URL pasted below…

    https://na2.salesforce.com/00T/e?what_id=0014000000XkAra&tsk1_lkid=$User.Delegate_ID__c&retURL=0014000000XkAra

    Any ideas how I can get it to read that field value? It reads the other ID values just fine, but maybe because the field type on this is ID, not text or a formula. ?

  29. William says:

    I forgot to add the code as it’s written…

    HYPERLINK(‘/00T/e?what_id=’ & Id & ‘&tsk1_lkid=$User.Delegate_ID__c&retURL=’ & Id, IMAGE(‘/servlet/servlet.FileDownload?file=01540000000jgyw’, ‘Delegated Task’),’_self’)

  30. Jason says:

    We have to create Opportunities from the Contact record in order to ensure the Contact is added to the Contact Roles on the Opportunity. I’m trying to create a Link as a Formula field (not a “Custom Link” or “Custom Button”) so that the link can be displayed in the Contact Related List on the Account Page Layouts, so the Rep can click “New Opp” as a link in on the Contact Record in the Contact Related List on the Account without having to drill into the Contact first. All I’ve done is go to the Contact, click “New Opportunity” which gives me the URL I need, which is working fine, except when I try to populate additional fields, like populating the Opportunity Name as the Account Name by default (instead of defaulting to blank) doesn’t work.

    The formula field looks like (on the Contact record, so “Id” is the Contact ID):

    HYPERLINK(

    “/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F” + Id + “&save_new_url=%2F006%2Fe%3Flookupcmpgn%3D1%26retURL%3D%252F” + Id + “%26accid%3D” + AccountId + “%26conid%3D” + Id + “%26opp6%3DMarketing&Name=” + Account.Name

    , “New Opp”)

    The link works great, takes me to the Create Opp, I select my record type, I fill in my fields on the Opp, save it, and the Opp is created with the Contact assigned in the Contact Roles…

    But the &Name=Account.Name isn’t working… it shows up in the URL address bar in the browser, but doesn’t populate the field in the Opp Edit page… I still have to manually type in an Opp Name. I also tried &opp4=Account.Name with no luck. Any ideas?

    • Ray Dehler says:

      Try opp3 instead of opp4. Opportunity Name is opp3 in my instance.

      • Jason says:

        That was it… Thanks for the quick reply!

      • Bill Johnson says:

        Hey Ray! I have a similar question to Jason, the difference being that I’m trying to populate the Name of a custom object that is a child of Opportunity. I’m all set with the lookup field being properly populated, and I can populate values into text fields (like “description”, etc) via an URL hack, but I can’t seem to populate the custom object name with the opportunity name as a default. Seems simple enough… Any ideas?

        /a0H/e?CF00N50000002PxxK={!Opportunity.Name}&CF00N50000002PxxK_lkid={!Opportunity.Id}&01I50000000Uk8D={!Opportunity.Name}&retURL={!Opportunity.Id}

        01I50000000Uk8D is the custom object’s name field. Hence, 01I50000000Uk8D={!Opportunity.Name}.

        Cheers!
        Bill

        • Ray Dehler says:

          Hi Bill-

          Strangely enough, I was able to reproduce this issue. Try “Name” as the key. In other words,

          /a0H/e?CF00N50000002PxxK={!Opportunity.Name}&CF00N50000002PxxK_lkid={!Opportunity.Id}&Name={!Opportunity.Name}&retURL={!Opportunity.Id}

          That worked for me anyway. The way I found it is by inspecting the element with the Chrome DOM inspector from the record edit page, then noticing the input’s id was “Name”.

  31. Vik says:

    Hi Ray,

    In my case the ID is getting populated in the URL but value is not displayed on my visualforce page.

    Here is my URL for the button: https://xxxx–xxxxxxx.cs9.my.salesforce.com/apex/inspectionreq?CF00NK0000000VMrx={!Establishment_Record__c.Name}

    and here is the URL for visualforce page but can’t see in VF page: https://xxxx–xxxxxxx–c.cs9.visual.force.com/apex/inspectionreq?CF00NK0000000VMrx=NBAT-ER-20120323-00014

    but the field (lookup) in my visualforce page is blank.

    Thank you!

    • Ray Dehler says:

      Vik-

      With lookups you need to both specify the value and ID. So you’d want
      CF00NK0000000VMrx={!Establishment_Record__c.Name}&CF00NK0000000VMrx_lkid={!Establishment_Record__c.Id}

      Ray

  32. Madhan says:

    Hi Ray,

    I have created a custom object called “Case Template” (Case_Template__c) and I need to prepopulate the value for the field Case Template name(OOB required field) while creating a record, How to get the “Case Template Name” ID?

    Thanks for your posts!

    Regards,
    Madhan Raja

    • Ray Dehler says:

      One thing you can do is go to the new record page for that object and view source. You will see an ID next to the label of the name field, this should get you what you want. Let me know if you need more detail.

  33. Arman says:

    Thanks Ray ! Great article !
    But I am trying to post an “Idea” as related to an Opportunity; so we want to pre-populate a custom lookup field within “Ideas” with the Opportunity Id.
    However, I noticed that “Ideas” seems to be a non-standard SF tab, and even its “edit” URL is like: ” https://cs1.salesforce.com/ideas/editIdea.apexp?c=09a3000000001YD& retURL=%2Fideas%2FideaList.apexp ”

    View URL example: https://cs1.salesforce.com/ideas/viewIdea.apexp?id=087S00000004NZ7

    Using a Button and a Controller, I was not even able to display the value of the “Idea.Title” standard field, let alone our custom lookup field.
    “Ideas” appears to be like an AppExchange product integrated into SF at some point. Any suggestions ?

    • Ray Dehler says:

      Arman-

      Yes, there are only a few ways you can configure the Idea module in Salesforce. I quickly looked over the idea submit page and didn’t see any easy way to default an idea category, sorry! I’m not saying it’s not possible, just that I couldn’t figure it out in 5 minutes.

      Ray

  34. Question on Quotes says:

    Hello,

    I am trying to use this url below to auto populate opp fields on to a quote and I am having issues. Some of the fields work while others do not. The Lead and phone fields work while all others fail. Any help would be appreciated. One more thing I would like to add is the ability to auto sync quote items with opp line items with out needing to click the sync button.

    /0Q0/e?retURL=%2F{!Opportunity.Id}&oppid={!Opportunity.Id}&name={!Opportunity.Name}&ExpirationDate={!Opportunity.CloseDate}&CF00N30000009PDzz={!Opportunity.Lead__c}&CF00N30000009PDzz_lkid={!Opportunity.LeadId__c}&Phone={!Opportunity.Phone__c}&email={!Opportunity.Email__c}&billingname={!Opportunity.Full_Name__c}&billingaddressstreet={!Opportunity.Bill_to_Address_1__c}&billingaddresscity={!Opportunity.Bill_to_City__c}&billingaddressstate={!Opportunity.Bill_to_State__c}&billingaddresszip={!Opportunity.Bill_to_ZIP__c}&shippingname={!Opportunity.Full_Name__c}&shippingaddressstreet={!Opportunity.Deliver_to_Address_1__c}&shippingaddresscity={!Opportunity.Deliver_to_City__c}&shippingaddressstate={!Opportunity.Deliver_to_State__c}&shippingaddresszip={!Opportunity.Deliver_to_Zip__c}

    Waylon

  35. Nivyaj says:

    I read the section on the lookupId and I’m having difficulty with 2 parts:
    1. Getting the actual field for the field I want to prepopulate ( I can get the relative name which is ‘evt_1′)
    2. populating a User lookup field with the User Name I want to prepopulate.

    Here is what I get when I inspect the element:

    Can someone advise me?

  36. Nathan says:

    I made a custom field of Case object as readonly in page layout and I need to set a value for this field in new case creation. Can you please help me how to set a value for this readonly field ? If I look in page view source html I do not get field id.

    • Ray Dehler says:

      I’m interested to see if that would work. Try to make it not read-only, for the purposes of getting the id, then read-only again to see if it passes it in.

      • Nithin says:

        We are also facing the same issue.Even if we pass the value for that field, if its read-only in page layout,the values do not display.I don’t think there is a workaround for this issue.
        Another interesting point to notice is, it works for a standard field which is by default read-only in page layout.

  37. Ruby says:

    This is an excellent post Ray.
    But can you please tell me what’s going wrong here when I am trying to pre-populate a field called Theatre(picklist field) on the Opportunity object with the Theatre value of the User who is logged in.

    This is the standard link for a new opportunity getting created:
    https://{org}/006/e?retURL=%2F006%2Fo&RecordType=012300000000Asg&ent=Opportunity
    I am just appending the field id for Theatre (00N40000001u8th) and assigning the user’s theatre field to it. So the URL now becomes:

    https://{org}/006/e?retURL=%2F006%2Fo&RecordType=012300000000Asg&ent=Opportunity&00N40000001u8th=$User.Theatre__c

    But this doesn’t seem to be working.

    Ruby

    • Ray Dehler says:

      The final URL has $User.Theatre__c, or does it actually have the corresponding ID?

  38. Rhonda Ross says:

    I saw that a couple of people asked about closing the record after it was created. Didn’t see any responses – but there are so many comments on this great post that I may have missed it. Sorry if this is a repost.

    This can be done by adding &save=1 to the URL.

    • Ray Dehler says:

      Excellent, thanks Rhonda!

      • One additional piece of information on &save=1

        Salesforce disabled this feature for new orgs created sometime after early last year. If I recall correctly, this was done to protect companies from some sort of potential cross scripting attack.

        To be able to use it you have to log a case with Salesforce support and ask for that ability to be turned on.

  39. Viv says:

    I have created a custom button on Quote object and have it on the layout for Account object.
    This is my Javascript for the button:

    /*
    {!REQUIRESCRIPT(“/soap/ajax/21.0/connection.js”)}

    if (!Objectname__Quote__c.Objectname__OpportunityId__c == “”) {
    window.parent.location.href =”/apex/Objectname__QuoteEdit?id={!Objectname__Quote__c.Id} & clone=true”;
    } else {
    window.parent.location.href = “/apex/Objectname__QuoteEdit?id={!Objectname__Quote__c.Id}&oppId={!Objectname__Quote__c.Objectname__OpportunityId__c}&clone=true”;
    }
    */

    On clicking the button I get an error saying “Objectname__Quote__c is not defined”.

    Any suggestions on this?

    Thanks

  40. Oded says:

    This is very helpful.

    I have one issue I still cannot get working: the new record I’m creating needs to be of a specific Record Type (it is always the same type).
    How do I fill the Record Type field with the type I want without going through the window that lets me select the Record Type?

    Any suggestions?

    Many thanks

    • Ray Dehler says:

      Hi Oded-

      It’s simple — when you create a new record and select the record type, there will be a record type specific parameter or two on the URL. Simply copy this into your custom button and you’re set.

  41. Alex says:

    Ray,

    Kindly help:
    https://emea.salesforce.com/006/e?00N20000000h2Rs={!IF(NOT(ISBLANK(Account.Users__c)),”00N20000000h2Rs={!Account.NumberOfEmployees}”,””)}

    I need to populate the field in Opportunity called Users (00N20000000h2Rs), this is the ‘number’ field.
    It has to be populated with the following criteria derived from the Account.

    1. If the Account has any number of users, then the field must update with the number of users.
    2. However, if number of users is blank but Account has Employees number, then Employees number should pass into the field in Opportunity.

    Much appreciate your thoughts.

    Regards,
    Alex

  42. Alex says:

    Hi Ray,

    Firstly, thank you for your review of the URL formula, much appreciate.

    1. You are correct, I don’t want a forumula on the Opportunity. This is a URL from Custom Button, that once the button is pressed, the opportunity is generated on the fly, deriving values from account fields and event fields and filling the opportunity fields.

    2. Both Account Employee and Account Users are “number” fileds.

    3. I have pasted your formula, however still says: Syntax Error (Content Source is URL)

    Could you kindly look at it again?

    Regards,

    Alex

    • Ray Dehler says:

      I was able to get this to pass without any syntax errors:

      /006/e{!IF(NOT(ISBLANK(Account.Users__c)),"?00N20000000h2Rs="+TEXT(Account.Users__c), IF(NOT(ISBLANK(Account.NumberOfEmployees)), "?00N20000000h2Rs="+TEXT(Account.NumberOfEmployees), ""))}
  43. Adrian says:

    Hi Ray,

    Is it possible to populate values when your field is set to read only?
    For example, my field is not a type of formula (Formula fields is not editable by default)
    but it is set to read only in my page layout. I tried doing the solution you’re suggesting above
    but it seems like the field should be always editable in the page layout so that it will work. What if it needs
    to be populated but read only?
    Any Ideas?

    Thanks,
    Adrian

    • Ray Dehler says:

      I just confirmed that if the field is read-only on the page layout to a profile, they cannot set it with URL-hacking. This is a good thing…

      If it needs to be set, I think the best approach might be to use a before insert trigger to do this. If it’s simple enough (read: a literal), you could do it with the field’s default value.

  44. Siddharth Majhi says:

    Hey guys .. I have a related question .. how to do URL hacking in case of multi select picklist fields?

  45. Robert says:

    Can someone please give a NON CRYPTIC example of this. I have a custom object that is a child of another custom object. Each of these are lookup fields in the Opportunity.
    I drill down to the Custom child and have Related list of Opportunities. From there I would like to simply add an Opportunity and have the TWO lookup fields pre populate. By default, only one is currently populating.

    • Ray Dehler says:

      Robert — many people have had success implementing this. Maybe it would be more helpful if you could detail exactly where you’re stuck?

      • Robert says:

        I have A custom object Called Referring_Org that is a parent of another custom object called Ref_Agent. Each of these are lookup fields in Opportunity. I drill down into Referring_Org to get a list of Ref_agents, then I frill down into Referring_Agents and see a related list of Opportunities of the Referring_Agents. From here I want to create a NEW button that fills in the Referring_Org and Referring_Agents lookup fields in Opportunity.

        These are my ids from the Opportunity lookup fields (Custom)
        Referring_Org CF00N70000002YWsr
        Referring_Agent CF00N70000002YWsh

        This is one version I tries just to try for the Ref_Agent
        …/006/e?&retURL=%2F{!Referring_Agent__c.Id}&CF00N70000002YWsh={!Referring_Agent__c.Name}&CF00N70000002YWsh_lkid={!Referring_Agent__c.Id}

        Note: The reason I have TWO lookup fields relating to the same parent child custom object is because there seems to be a limitation in referencing “Grandchildren” in some other items.

        Any help woule be GREATLY appreciated…and will keep me from blowing my head off. lol

      • Robert says:

        Also. If you could point me toward any detailed documentation on Salesforce object referencing, that would REALLY help. Im getting lost in __c and __r and the orders etc.

      • Robert says:

        GOT IT!!! I was trying to test the page by simply pasting the custom URL in the address bar and kept getting the {field__c} in the input box. When I created the actual custom “New” button and added the formula for the URL there is functioned perfectly. Somehow the actual custom button renders the display value correctly where simply pasting the URL did not.

        • Ray Dehler says:

          Good to know, thanks for following up, Robert.

          • Peter says:

            FYI, this also happened to me: It was simply pasting in the {!Object.Name} text verbatim into the field when I did the ‘paste URL’ method. However when I actually integrated it into a new button, it worked great!

            Perhaps this has something to do with my browser? Google Chrome, FYI.

          • Ray Dehler says:

            Strange, haven’t seen that before.

  46. Nithin says:

    Hi,
    I want to populate Custom Lookup field (which is not in page layout), from the click of button at related list.
    U have any idea on this..

  47. Reuven says:

    How can this method be used to populate a Lookup(Contact) field on an Opportunity record, with the Contact Name of that Opportunity’s Primary Contact Role?

    • Ray Dehler says:

      You may need something a tiny bit more complex in this case, because the Primary Contact Role has to be selected via SOQL, you’d need either apex or javascript with a connection to do it.

  48. LizKS says:

    Hi Ray,

    Thank you so much for this post. This has been so helpful! The only thing I’m having issues with is that I’m going crazy trying to populate the Account Name on a Contract that I am creating from the Opportunity. So on Opportunity I have replaced the New Contract button and it is working great, except that I can’t get the Account Name (lookup) on the Contract to pull in the Opportunity Account. I’m going crazy! I’ve tried all kinds of combinations like Account, accId, Account_lkid, accId_lkid and then on the other end {!Account.Id}, {!Opportunity.AccoundId},{!Opportunity.Account}… I can’t seem to find what works! I feel like this should be a simple fix and I’ll probably slap myself in the forehead when the solution is revealed!

    • LizKS says:

      Got it! I read all these replies and saw the string about case sensitivity… looks like maybe it was because of the case accid instead of accId. UGH! so this finally worked – accid={!Opportunity.AccountId}. So happy this is working now! Thanks again…

  49. Bob says:

    Thanks for you posts on hacking URLs. Very helpful, but I’ve run into a problem trying to use an IF statement with merge fields.

    In reviewing other posts, I’ve included the following statement in a formula for a custom button:
    {!IF(NOT(ISBLANK(Opportunity.Location__c)),”CF00N80000003pdK4={!Opportunity.Location__c}”,””)}
    I’m doing this as an empty Opportunity.Location__c produces an error on the page.

    My problem is that the merge field is not being evaluated and the URL appears as “CF00N80000003pdK4%3D%7B%21Opportunity.Location__c%7D” instead of “CF00N80000003pdK4=Ashburn” as I would have expected (assuming that “Ashburn” was the value of Opportunity.Location__c).

    Any ideas?

    • Ray Dehler says:

      In other words, it’s HTML encoding your string, which is not what you want. I’d have to see the entire story, here. Contact me if you’d like more help troubleshooting.

  50. Heather says:

    Great post!
    I’m trying to do the same with user lookups. I noticed there was another post specific to user lookups between Chris, Carol, and Ray back in January, but I don’t see the final answer posted. Can you share the trick to get user lookups to populate correctly using the URL hack? Thanks!

    • Ray Dehler says:

      Heather — you’re talking about this thread. I think the problem specifically there was for using CF at the beginning. Ask your question and you’ll likely get a response here.

      • Heather says:

        Hi Ray,
        Here’s the challenge I’m having. I want to create child records (change control) from my master record (esolutions project) and have certain user lookups from project automatically populate user lookups on the child change control records. Here’s the code I have so far that works great for populating the project lookup on the change control record, but doesn’t work for the user lookup called First Escalation. Any ideas of what needs to be corrected?

        /a11/e?CF00N00000008kSUZ=” & First_Escalation__r.FirstName &” ” & First_Escalation__r.LastName
        & “&CF00N00000008kSUZ_lkid=” & First_Escalation__r.Id
        &CF00N00000008kSTx={!eSolutions_Project__c.Name}&CF00N00000008kSTx_lkid={!eSolutions_Project__c.Id}

        Thanks in advance for any help you can offer! In the thread you mentioned previously, there’s a note that you emailed Carol with a resolution. Perhaps you could post that resolution?

        Heather

        • Ray Dehler says:

          Hi Heather — Carol’s email has no content.

          The way I generally approach this is to see what is the resulting URL that has these values merged in. I can’t just spot check and find out what’s wrong, it looks correct to me. What is the resulting URL when these values are merged in — is something missing?

  51. sp92100 says:

    my case is slightly different . need little help:

    I am trying to create a child record from a visualforce page. New button have below code but it won’t pre populate Account Name (master) in the child record?

    btr_stores is a custom object to account (master detail)

    thanks in advance.

  52. Rob says:

    To pre-populate a standard field for any object, it appears that you have to use the id of the field as it appears in the HTML source on the page, not the API name for the field. For example, on Leads you can pre-populate the “First Name” & “Last Name” fields like this:

    https://naN.salesforce.com/00Q/e?name_firstlea2=Rob&name_lastlea2=Smith

    These are the IDs of the fields in the HTML source on the page, not the API names for the fields. You may need to inspect the source code for your records as I am not sure if they are the same in every instance.

    HTH,

    — Rob

  53. nawshine says:

    Hi Ray, That’s a great article indeed & great follow ups and replies. I’ve got a question too
    I am overriding the New button in a related list and have defaulted a few values (as described) – and it works like a charm. We now have an additional functionality to select record types before redirecting to custom object’s page and Im not sure how to implement ths. I’ve seen examples with a single recordtype Id being hardcoded but I need the record type picklist page for the user to first select the record type and the be redirected to the object’s page with the defaulted values.
    Jason’s questions looked a bit similar (03/04/2012), but I am overriding the button using url (not VF page) would you mind help me out on how to integrate the recordtype picklist in my url. My url is as follows:
    /a0D/e?Name={!$Label.AutoName}&CF00NJxxxxxxxVANU_lkid={!Dossier__c.Id}&CF00NJxxxxxxxVANU={!Dossier__c.Name}&retURL=%2F{!Dossier__c.Id}&nooverride=1
    Thanks

    • Ray Dehler says:

      nawshine — I’m guessing you need to put your variables URL encoded inside the retURL in that case.

      • Jason P says:

        Thank you, thank you, thank you!

        I was able to code in the variables URL, however, I’m now missing the master name (in this case, the Opportunity name). Could you tell me where I’m going wrong? I’m soooo close!

        /setup/ui/recordtypeselect.jsp?ent=01Id0000001Fmqu&retURL=/{!Opportunity.Id}

        &save_new_url=/a0T/e?CF00Nd0000007NktV={!Opportunity.Name}

        &CF00Nd0000007NktV_lkid={!Opportunity.Id}

        &retURL=/{!Opportunity.Id}

        &ent=01Id0000001Fmqu

        &Name=Auto-Populated

        &CF00Nd0000007NkuE=Specific+Person

        &CF00Nd0000007Nl02_lkid={!Opportunity.Managing_Director_luId__c}&CF00Nd0000007Nl02={!Opportunity.Managing_Director_lu__c}

        &CF00Nd0000007Nl0_lkidC={!Opportunity.Claims_Manager_luId__c}&CF00Nd0000007Nl0={!Opportunity.Claims_Manager_lu__c}

        &CF00Nd0000007Nl0g_lkid={!Opportunity.Underwriting_Director_luId__c}&CF00Nd0000007Nl0g={!Opportunity.Underwriting_Director_lu__c}

        &CF00Nd0000007Nl28_lkid={!Opportunity.Risk_Manager_luId__c}&CF00Nd0000007Nl2={!Opportunity.Risk_Manager_lu__c}

        &CF00Nd0000007Nl0M_lkid={!Opportunity.Client_Analytics_ManagerId__c}&CF00Nd0000007Nl0M={!Opportunity.Client_Analytics_Manager__c}

        &CF00Nd0000007Nl0W_lkid={!Opportunity.ActuaryId__c}&CF00Nd0000007Nl0W={!Opportunity.Actuary__c}

        • Ray Dehler says:

          Thanks for the email. As I noted in the email, I think the root cause is the trailing and leading spaces in your button code, which translates into + symbols. Give it a shot, thanks!

  54. Sathead3 says:

    Great Post indeed Ray. Is there anything specific I should know about setting date fields? I am creating a URL in a VF controller and pre-populating fields just fine but it does not seem to be working on date fields. The URL string that’s setting it looks like “…&CF00NS0000001CDZ2=2012-11-15+00%3A00%3A00″ but does not work. I am reading the date value from another object in my controller. I tried to manually manipulate the string to see the effect and 2012-11-15 or 11/15/2001 etc do not seem to work for me. I’ll keep hacking but thought I’d post and check. Thanks,

    • Ray Dehler says:

      Sathead3 — I was able to get this working for a DateTime field:
      &00NF0000008hTLa=10%2F23%2F2012%204%3A19%20PM
      which is 10/23/2012 4:19 PM

      I’m guessing the format accepted depends on the user’s Locale settings.

  55. Ralph says:

    Ray, thanks for pulling together all the information into one easy to understand post!

    I’m trying to create a new lead. Not having any success, I’ve pared it all the way back to the basics, but still no luck. Here’s what the URL gives me when I create a new lead through the SFDC menu’s:

    https://cs14.salesforce.com/00Q/e?retURL=%2F00Q%2Fo&RecordType=012800000007Cs0&ent=Lead

    I’m assuming the retURL parameter is not necessary (indeed, hacking the URL to:
    https://cs14.salesforce.com/00Q/e?RecordType=012800000007Cs0&ent=Lead
    works just fine).

    But when I set my Button URL to:
    00Q/e?RecordType=012800000007Cs0&ent=Lead

    Salesforce gives me a “URL no longer exists” message, and the url in the new window is transformed to
    https://cs14.salesforce.com/servlet/00Q/e?RecordType=012800000007Cs0&ent=Lead

    Is this not working because of the Winter 13 update, or is am I missing something more fundamental? Based on what I’m reading here, it should just work.

    Thanks,
    Ralph.

    • Ralph says:

      Answer:

      Button link needs to be this:
      /00Q/e?RecordType=012800000007Cs0&ent=Lead

      The leading slash is very important!

      Lesson to self: Pay attention to details if you want this to work…

  56. Alyssa Marcucci says:

    I want to pull a relationship, similar to pulling a field in a formula, using the .r function. For example, I have a custom object Closing with a custom button to create a record in a Comp object that pulls the fields and relationships from the former into the latter. I also want to pull the fields from a 3rd object: Property, which has been pulled from the Closing to the Comp. From the Property, I wan to pull Building class into the Comp, see below for an example.

    /a08/e?RecordType=012E00000001fnF&CF00NE0000003ZtvM={!rethink2__Closing__c.rethink2__Property__c}&CF00NE0000003ZtvM={!rethink2__Closing__c.rethink2__PropertyId__c}& 00NE0000003ZtKA= {rethink2__Property__r.!Id}However, building class is not pulling over from the property. What am I doing wrong?

  57. Manish says:

    I am trying to pass custom field of ‘currency’ type from Account object to another currency field in a Custom object ‘XYZ’ (related list of Account) through a new custom button. In the URL, the currency value is being passed along with the currecy code.. i.e., SGD 9,000,000. The same is populated in the custom field, so it gives me an error – ‘Invalid currency’ as the currency field only accepts numbers not the text(SGD). If I take out SGD manually after it is populated and save the record, I get no error.

    I need to make sure SGD is not passed in the URL. I tried SUBSTITUTE and others,but nothing worked. Any ideas?

    • Ray Dehler says:

      Manish — this is strange, I haven’t seen currency fields include the currency before. I suppose you could do a regular expression in javascript to only include numbers.

      • Michael Rave says:

        The following piece of code will work, my example is based on passing the Opportunity Amount:

        {!LEFT(TEXT(Opportunity.Amount),LEN(TEXT(Opportunity.Amount))-3)&”,”&RIGHT(TEXT(Opportunity.Amount),2)}

        • Susan Troen says:

          Hi Michael,

          I tried your code but I get a syntax error. Your code looks right, so I’m a bit stumped. Any ideas?

          Thanks!

  58. Kevin says:

    Ray! Thanks for this post. I recently took over our salesforce instance (last week) without having any actual admin experience. I’m desperately seeking info on how to setup a custom button for a new object I created. Right now our sales reps will have to save the record then task me from a 2nd page — I’m hoping there’s a way to create a custom button that will save the record and load the task option with pre-populated fields.

    Any way you’d have a moment to give me some advice on this?

    • Ray Dehler says:

      Kevin — give this page a read, it describes exactly what you want to do.

      • Kevin says:

        This is what I’ve got so far for my custom button, I’m pretty lost from here.

        The object is called “Work Order,” after they fill in the object info the button “Submit Work Order” should save and task me. I don’t know what else to do.

        00T/e?
        what_id={This should be connected to the Work Order object
        tsk1=Kevin R
        tsk5=New Work Order
        tsk4={!Today}&
        tsk3=((Work Order Name – don’t know what to put here))
        retURL=%2F

        Anybody?

        • Kevin says:

          Ok, so this is what I’ve got, but I get

          “Unable to Submit for Approval
          This record does not meet the entry criteria or initial submitters of any active approval processes.”

          00T/e?
          what_id={!Work_Order__c.OpportunityId__c}
          tsk1=Kevin R
          tsk5=New Work Order
          tsk4={!Today}&
          tsk3={!Work_Order__c.OpportunityId__c}
          retURL=%2F{!Work_Order__c.OpportunityId__c}

  59. Brian Kessler says:

    Good morning, Ray!

    This article seems most helpful and I’m selfishly delighted to see you’ve been helping your readers debug.

    I’m hoping your still active on this since I’m currently struggling to get a button URL right.

    Long story made short:

    We have two custom objects (“Needs Request” and “Vacancy”).

    When the “Activate” button on “Needs Request” is clicked, we want a new “Vacancy” object to be created and 6 fields to be populated.

    Four of the fields (“Job Title”, “Job Type”, “Grade”, and “Business Function”) are all working perfectly.

    Two of the fields (“Related Request” and “Location”) are not working at all.

    “Related Request” is a lookup back to the “Needs Request” sObject.

    “Locaton” is a multipicklist on both sObjects, but we don’t want to use a formula (maybe because some Vacancies may not relate back to Needs Requests.

    Here is the link for the button as it presently stands:

    /a0g/e?retURL=https%3A%2F%2Fc.cs7.visual.force.com%2Fapex%2Foverride?
    CF00NM0000000fKQD={!Needs_Request__c.Name}&
    CF00NM0000000fKQD_lkid={!Needs_Request__c.Id}&
    00NM0000000f27G={!Needs_Request__c.Job_Title__c}&
    00NM0000000esuI={!Needs_Request__c.Job_Type__c}&
    00NM0000000eto6={!Needs_Request__c.Grade__c}&
    00NM0000000etm0={!Needs_Request__c.Business_Function__c}&
    00NM0000000esuS={!Needs_Request__c.Location__c}

    … Any help from either you or the “peanut gallery” will be greatly appreciated!

    Best regards,

    -Brian.

  60. Manish says:

    Here’s the solution for multi – select picklists

    Use on click javascript as the Behavior, not URL.

    Let’s say we have a picklist called ‘Interests’ on Contacts, a custom field with a Salesforce ID of 00N20000000xXxX, with the following values:

    Basketball
    Football
    Rafting
    Climbing
    Tennis

    The objective of our custom button will be to take these values from an existing contact record and populate a new one. Let’s say that the end-user had chosen Basketball, Football, and Climbing on the record from which to click the button. Once the button is clicked, the button must be able to create a new parameter for every selected value. The end result must like the following:

    https://xx.salesforce.com/003/e?
    00N20000000xXxX=Basketball&
    00N20000000xXxX=Football&
    00N20000000xXxX=Climbing

    Now, when creating the button, our picklist {!Contact.Interests__c} is only capable of returning each selected value separated by semi-colons, for instance: Basketball;Football;Climbing. As there is no formula function designed to easily format this, we must use Javascript to split the values of {!Contact.Interests__c} into an array, then pair it with the field ID as a parameter in the URL every time it occurs. The following code is an example of how to do this:

    var mplVals = “{!Contact.Interests__c}”;
    var mplSFID =”00N20000000xXxX”;
    var mplVals = mplVals.split(“;”);
    var params = “”;
    for (var i=0;i<mplVals.length;i++){
    params = params + mplSFID+ "=" + mplVals[i] + "&";
    }
    var URL="/003/e?"+ params;
    parent.frames.location.replace(URL);

    • Ray Dehler says:

      Thanks for sharing, Manish.

      • Ryan Lorenzen says:

        var mplVals = “{!Contact.Interests__c}”;
        var mplSFID =”00N20000000xXxX”;
        var mplVals = mplVals.split(“;”);
        var params = “”;
        for (var i=0;i<mplVals.length;i++){
        params = params + mplSFID+ "=" + mplVals[i] + "&";
        }
        var URL="/003/e?"+ params;
        parent.frames.location.replace(URL);

        Can you break that code down? I see where to insert the API name and field ID at the top, but what else do I need to do?

        And where do I insert my URL to populate the other fields?

      • Trevor Heywood says:

        Thanks Ray for a superb page which has helped me enormously!

    • Trevor Heywood says:

      Hi!

      I’m new to Salesforce and to Javascript. I have tried to put my version of this code onto a button as “OnClick Javascript”. However when I try the button I just get the message: “A problem with the OnClick JavaScript for this button or link was encountered: Unexpected identifier”.
      Not sure what I’m doing wrong here, but I need to get the multi-select picklists working with the other fields (which were working using the “URL” method. Here is my code:

      var mplVals = “{!Contact.Bench_022_Secondary_Client_Group__c}”;
      var mplSFID = “CF00Nb0000006qNwD”;
      var mplVals = mplVals.split(“;”);
      var params = “”;
      for (var i=0;i<mplVals.length;i++){
      params = params + mplSFID+ "=" + mplVals[i] + "&";
      }
      var URL="/a0M/e?CF00Nb00000024YLM=" + {!Contact.Name} + "&01Ib00000009Rk8_lkid=" + {!Contact.Id} + "&00Nb00000066Woh=" + {!Contact.Phone} + "&CF00Nb0000006pYjJ=" + {!Contact.Bench_Initial_Referrer__c} + "&00Nb00000066WGM=" + {!Contact.Bench_021_Primary_Client_Group__c} + "&" +
      params + "retURL=/" + {!Contact.Id};
      parent.frames.location.replace(URL);

      All help gratefully appreciated!

      Trevor

      • Trevor Heywood says:

        Result! I have managed to fix this, mostly through luck rather than judgment ;-). I enclose the finished code below in case this is of use to anyone. It is adding a detail record (custom object called “Assessment”) from a button on the Contact, which is the master in the relationship. Various fields are defaulted on the new detail record automatically from the master, including a multi-select picklist (“Secondary Client Group”).

        Working code:

        {!REQUIRESCRIPT(“/soap/ajax/29.0/connection.js”)}

        var mplVals = “{!Contact.Bench_022_Secondary_Client_Group__c}”;
        var mplSFID = “00Nb0000006qNwD”;
        var mplVals = mplVals.split(“;”);
        var params = “”;
        for (var i=0;i<mplVals.length;i++){
        params = params + mplSFID+ "=" + mplVals[i] + "&";
        }
        var URL="/a0M/e?CF00Nb00000024YLM={!Contact.Name}&01Ib00000009Rk8_lkid={!Contact.Id}&00Nb00000066Woh={!Contact.Phone}&CF00Nb0000006pYjJ={!Contact.Bench_Initial_Referrer__c}&00Nb00000066WGM={!Contact.Bench_021_Primary_Client_Group__c}&" +
        params + "retURL=/{!Contact.Id}";
        parent.location.href = URL; //refresh the page

  61. Mike Ryan says:

    I have a custom object with several record types, I want to populate lookup field account (custom object field also called Account) when Contact lookup field is entered (also called contact on custom object). I need help, I am an admin. looking to upgrade my Users efficiency and usability. Help me.

    • Ray Dehler says:

      And at which stage do you want it to occur? This seems like a good use case for a workflow field update, perhaps.

      • Mike Ryan says:

        Can’t get workflow to work because it is a lookup field, I am in a custom object, I enter the contact field lookup field, it seems to me since the contact is associated to one account, I can get that account lookup field automatically populated.

        • Ray Dehler says:

          Ah yes. Well, then I’m afraid you’ll either have to do it in a trigger or a visualforce page, depending on which stage you want it to occur.

  62. Petya says:

    Hello Ray

    I`ve spent so much time with this issue, until I found your site.
    I try to display a user lookup field from the account on the opportunity.
    The field is filled on the account, and calls „Engineer“. When the user defines an opportunity to this account, the same field on the opportunity must be filled.
    So I defined a custom button „new Opportunity“ and wrote following code:

    /006/e?CF001L0000004y3Pi={!Account.Name}& CF001L0000004y3Pi_lkid={!Account.Id}& CF00NL0000000HSA8={!Account. Engineer__c}&retURL=/{!Account.Id}

    CF00NL0000000HSA8 this is the ID of my Engineer field
    001L0000004y3Pi this is account ID

    My „Engineer“- field on the opportunity is still not auto populated.
    Any advices or ideas?

  63. Linda Johnson says:

    This site has been extremely helpful. I have a button that when clicked needs to mark a check box field true (which it does) and auto save the record and return the user to the record (which it does not do). I do not want my users to have to also push the save button. Defeats my purpose. Any help would be appreciated. BTW the error message I get is”
    The page you submitted was invalid for your session. Please click Save again to confirm your change.

    My code is as follows:

    “/{!Case.Id}/e?
    00Na000000A7RDP=1
    &save=1
    &retURL={!Case.Id}”

    • Linda Johnson says:

      Just found the answer from a previous post

      One additional piece of information on &save=1

      Salesforce disabled this feature for new orgs created sometime after early last year. If I recall correctly, this was done to protect companies from some sort of potential cross scripting attack.

      To be able to use it you have to log a case with Salesforce support and ask for that ability to be turned on.

  64. Naresh says:

    I have two custom Buttons in the same Object Current year and Next year. If i click on the Next year button. I want to get the filed values to be get auto populated through url. How can we achieve it.

    fields on Currenty year : name, Account, Strenght and weakness.
    i want to get these fields in Next year Button.

    This is the Url I am Using : window.top.location=BPUrlForNew+’?’+CFID+’=’+AccountName+’&’+CFID+’_lkid=’+aid+’&RecordType=’+BPRecordId

  65. EChoice says:

    Thanks so much for this! I made a button that converts Opportunities to a custom Object “Deal”

    Everything works perfectly except for a few things:

    1) I have two currency values that must go to 6 decimal places, but during the transfer both values round to the second decimal place.

    Rounding still takes place regardless of if both fields are set to currency or number (with 6 decimals).

    2) The Opportunity Name won’t copy to the new Deal Name

    Since Deal Name is a standard field I’ve been using the merge field instead of the ID.

    It would be great if you could give me a few suggestions.
    Thank you for your help!

    • Ray Dehler says:

      Hi EChoice — I confirmed that there’s no way to get this value using standard merge fields. You can, however, get this with url hacking and a javascript button. Consider the following as an example.

      {!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
      
      var query = "SELECT CurrencyField__c FROM ObjectMaster__c WHERE Id = '{!ObjectMaster__c.Id}' limit 1";
      
      result = sforce.connection.query(query);
      records = result.getArray("records");
      
      if(records[0]) {
        var master = records[0];
        var currencyField = master.CurrencyField__c;
        document.location.href = '/a0B/e?00NF0000008hZkI='+currencyField;
      } else {
        alert('There was an error.');
      }

      I was able to get 6 characters to show up after the decimal.

  66. Guillermo says:

    So can you give me a good example of EncodingUtil.urlEncode() ? I know how to encode special characters into url encoding switch suc h as %20 etc. But I recently fell into an oddity where my field forumla returns

    Short version of my formula field url code:
    ——————————————-
    HYPERLINK(
    “/800/e?RecordType=012500000001ODT” &
    “&CurrencyIsoCode=” & TEXT(CurrencyIsoCode) &
    “&ctrc5=” & TEXT( MONTH( Agreement_Signed_Date__c ) ) & “/” & TEXT( DAY( Agreement_Signed_Date__c ) ) & “/” & TEXT( YEAR( Agreement_Signed_Date__c ) ) &
    “&retURL=” & Id
    , “Generate Fleet-Route Contract Summary” , “_blank” )

    Displayed Output: (why would there be “_HL_Encoded_” at the beginning of the output???)
    ——————-
    _HL_ENCODED_/800/e?RecordType=012500000001ODT&CurrencyIsoCode=USD&ctrc5=9/25/2012

    • Guillermo says:

      I guess my real question is, how can I wrap the Account.Name value to encode the output? It seems when special characters show up in a text field such as &,. things break and stop immediately at that line? I did test my formula by stripping out each componenet, and narrowed it down to two lines:

      “&ctrc7=” & Account.Name &

      AND

      “&ctrc25street=” & Billing_Street__c &

      In most cases the output works fine, but when & or . show up in the text value from the account record, it kills the url formula. Can I wrap a field in some kind of encode function? This is all related to a Field Formula, not button code.

      • Ray Dehler says:

        What you want is to be able to use URLENCODE() in this context, but you cannot from a formula field. If you could refactor this to be a button instead, you could make it URL type, so it does the encoding for you when you merge the text field.

        EncodingUtil is to be used from apex, but in this case, I’d say avoid it if at all possible.

    • Anu says:

      Hi Guillermo,

      Am anu, salesforce developer, i am facing the same issue which u have faced it, i just want to know did that issue got solved.

      I have used formula field to show up the data as hyperlink and users get navigated from thr: this is what i have used

      HYPERLINK(“/apex/BSureC_Discussions?Custid=”&Customer_ID__r.Id & “&type=”&Discussion_Type__c & “&mode=”& On_Going_Credit_Id__c & “&id=”&Id , TitleDescription__c,”_self” )”)

      Is working fine whenever am creating a new record but my issue when we are doing Data migration, so for some of my data its shows up like

      _HL_ENCODED_/apex/BSureC_Discussions?Custid=a0Kd0000006Oh7l&type=File&mode=COGCS-076857&id=a0Rd0000003ZSow_HL_NFMCG Credit Meeting Discussion Notes 02172011Document posting_HL__self_HL_

      Can you please help to solve this issue.

      Thanks in advance
      Anu.

  67. Karin says:

    Hi,
    I’ve been struggling with this “new child object record” button, and I can’t seem to understand what I’m doing wrong:
    I have a Case child-object: Escalation.
    Excalation.Case (Master-Detail): 00N80000005Cgqc
    Excalation.Account (Lookup): 00N80000005Cgtb
    Button URL:
    /a0G/e?CF00N80000005Cgqc={!Case.CaseNumber}&CF00N80000005Cgqc_lkid={!Case.Id}&00N80000005Cgtb={!Case.Account}&00N80000005Cgtb_lkid={!Case.AccountId}&retURL=%2F5008000000LTZwi

    Result:
    When I click the “new record” button – the Case name is populated correctly from the case, but the Account – remains empty.
    In the URL I do see all values properly:
    https://na6.salesforce.com/a0G/e?CF00N80000005Cgqc=12345&CF00N80000005Cgqc_lkid=TheCaseID&00N80000005Cgtb=CaseAccountName&00N80000005Cgtb_lkid=TheCaseAcocuntID&retURL=%2F5008000000LTZwi

    Can you please help me understand what am I missing, in order to properly populated the Account in the new escalation (i.e. default it from the Case)?

    Thanks,
    Karin.

    • Ray Dehler says:

      Try this instead
      /a0G/e?CF00N80000005Cgqc={!Case.CaseNumber}&CF00N80000005Cgqc_lkid={!Case.Id}&CF00N80000005Cgtb={!Case.Account}&CF00N80000005Cgtb_lkid={!Case.AccountId}&retURL=%2F5008000000LTZwi

      The difference is that I prepended CF to the IDs for the Account lookup.

      As far as I can tell, whenever it’s a custom lookup field (as Excalation.Account__c is), then we need to prepend CF. If it’s either not custom, or not a lookup field, we don’t need CF.

      • Karin says:

        Oh, right… I missed the “CF” part in this great blog.
        Awesome! It works well now, thanks!

        One last question (I hope):
        I’m trying to pre-populate a rich-text field on the custom object from an Account rich-text field.
        It’s not populating.
        Only if I turn the custom object field into a long-text type – it does.
        Am I missing something for working with the rich-text, or this is a limitation?

        Thanks again,
        Karin.

        • Ray Dehler says:

          It would appear as though RichText is a limitation, it does not work with url hacking. The implementation for RichText uses an iFrame behind the scenes, so it’s not as simple.

          You can still accomplish this with a visualforce page; it’s not as simple or elegant of a solution, but it would look the same to the user.

          • Karin says:

            Thanks.
            I’m not so familiar with visualforce pages yet, so I’ll live with that for now.
            Thanks.

  68. Aneta says:

    This is very helpful, thank you for posting.
    I have couple questions though. I have a Proposal custom object that is related to the Opportunity object and I’m coppying some fields from the opportunity into the proposal record. Everything works, but…
    1. I was wondering if it would be possible pre-populate the ProposalID field with a concatenated value (Example: “Prop -” & Opportunity.Name & ” – ” & Today())?
    I have the ID set to a text (not Auto-Number) but don’t seem to be able to populate it. I tried setting it to just the Opportunity name but it won’t display it. Is there a trick to it, or is this not possible with the ID field?
    2. I have a Solution Architect field on the Opportunity (user lookup field) which I would like to copy to the opportunity. How would I go about that? I was able to pass the Opportunity Owner from the opportunity to the proposal, but can’t figure out how to do the same with th Solution Architect field.

    Thank you in advance for your help and ideas.

  69. Ann says:

    This has been very helpful. I have created a custom button to pre-populate fields on the Send Email page.
    I have an IF statement to determine what value I display in the From field. The value passes correctly into the field and looks good from the Send Email page.
    We are using email to case, and have setup Organization-wide addresses. The address I am passing in the button is one of the Organization-wide addresses.
    Resulting email I receive lists the name correctly, but followed by duplicated email address strings, example: “My address” .
    How can I remove the duplicated email address, so it displays in the email that is received as “My address” .

    • Ann says:

      My full example did not display. Trying to display differently.
      “My address”

      • Ray Dehler says:

        I’m guessing it still doesn’t look right? Try applying html special chars, e.g. &lt; instead of < and &gt; instead of >. Shoot me an email, maybe I can help you out here.

  70. Ann says:

    sorry still not picking up the text I entered, using * to represent the bracketed email address.
    “My address” *email address* *email address*

  71. Wyan says:

    I’m having an interesting issue when trying to create a new campaign from a contact record. I want to populate the campaign with the contact information, and I’m pulling this into a custom lookup field on the campaign record, which displays the contact name. I’m able to display the contact name properly, but the look up is failing because of the id. This is the relevant part of the URL:

    CF00N90000004Bj8B={!Contact.Name}&CF00N90000004Bj8B_lkid={!Contact.Id}

    The problem seems to be that we have a custom field on the contact record call ID (ID__c), which is a unique identifier for each contact for organisational purposes. It’s a much shorter number, like 1124, and helps staff contact and track contacts.. I’m trying to use {!Contact.Id} to call the system record number for the contact record, and instead it’s pulling the shorter organisational id, which means the lookup fails. I don’t see why this should be happening, after reading all the comments I would have thought that if I wanted to call the ID custom field I would have to find the id for the custom field and use this. Why is {!Contact.Id} calling this custom field?

  72. Moderatelyfunky says:

    Thanks for this article. I’m hoping you might see something obviously wrong with this. I stripped it down to the one standard picklist that isn’t populating on the Opportunity. I’ve had luck with all the other fields I’ve wanted to populate, including a standard picklist. I’ve looked at the html and the ids and case look correct to me.

    https://cs15.salesforce.com/006/e?retURL=%2F006%2Fo
    &opp17_lkid={!Product_Interest__c.CampaignId__c}
    &opp17_lkold={!Product_Interest__c.Campaign__c}

  73. Moderatelyfunky says:

    Bingo. Thanks a million.

  74. Charan says:

    Hi,
    Can anybody help me on this please.

    I have two objects.1) Opportunity 2) Project

    I have 2 custom fields on both objects called i) Business Unit ii) Practise.
    Now, I created an Opportunity. In the related list I get Project. If I click on Projects, it redirects to Projects Object. In that I have to auto populate the field values which I already entered in Opportunity object. Also I have to auto populate Account name in Projects object.

    Thanks,
    Charan

  75. Pingback: Sending Visualforce Pages as Email Attachments in Salesforce | Michael Welburn

  76. Vidhya says:

    Ray, This is an awesome post. I have a question: is there a way to set one of the fields non editable/editable?

  77. Traci says:

    This is awesome. It helped me get 90% complete but I’m still having an issue that I hope you can help with. We have 3 different types of opportunities where all the fields are filled out a certain way. I’m trying to create a button for each and have no problem with any of the custom fields but I can get two standard fields that are pick lists to populate using my button. The two fields are Opportunity Type and Opportunity Stage. I’ve tried using the merge field and field name but neither work. I don’t know how to find the ID of a standard field as in the URL it only has “Type” or “Stage”. Can you give me a little direction on how to get this to work? Here’s what I have that is working:

    /006/e?retURL=%2F{!Account.Id}
    &accid={!Account.Id}
    &opp3={!Account.Name} “- Refresh”
    &00NA0000003oRKi={!Account.Website}

    • Traci says:

      Never mind. I think I was too tired and it made me brain dead. I figured it out in that I needed the field # (opp6, opp12) instead of the name. Doh! Everything is working now. Thanks so much for this site. I couldn’t have done it without you! :-)

  78. Pingback: Salesforce URL Hacking (Properly) | Frank Neezen

  79. DCT says:

    Does the URl hacking method work in case of multi-level objects.

    I am working on creating Conract from an Custom Object X which is a child of Opportunity.
    The relationship as follows:

    Object X is a child of Opportunity
    Contract is a Child of Object X

    When I create anew contract from Object X, the Account Name of the Opportunity should be auto populated.

    Can this be done?

    • Ray Dehler says:

      So you’re talking about populating
      Contract.Field_Name__c = Contract.Object_X__r.Opportunity.Account.Name
      is that correct?

  80. Varun says:

    Hi Ray,

    Liked you post and been trying the approach mentioned but no luck .

    I am trying a simple scenario first – I need to populate some standard fields of standard Account object to standard fields of standard child Opportunity object and what I tried for URL was – 006/e?Name={!Account.Name}&accId={!Account.Id}&retURL={!Account.Id}

    When I try to create a new Opportunity from the custom button where this URL is stored , I get an error about URL no longer exists.

    I also noticed in various queries (of TraciOpportunity, Moderatelyfunky etc. ) opportunity fields referred as – opp3, opp6, opp14.

    Please help in getting to know what these names are basically and how to get those names along with their significance .
    Any Salesforce documentation regarding the same for Opportunity and other such standard objects ?

    Please correct me to follow the right approach.

    Thanks ,
    Varun

    • Ray Dehler says:

      Hi Varun-

      Without looking too much at your request, I noticed that your URL doesn’t start with a forward slash (/), which would case this error about the URL no longer existing. Try changing the URL from
      006/e?Name={!Account.Name}&accId={!Account.Id}&retURL={!Account.Id}
      to
      /006/e?Name={!Account.Name}&accId={!Account.Id}&retURL={!Account.Id}
      and report back, thanks.

  81. John Braun says:

    Hello!

    I was hoping if I could help with the following scenario:

    I would like to create a custom button on the opportunity object that would do the following multiple tasks upon being clicked:

    1. Update 2 fields on the opportunity record and save the record
    2. Create a related quote record by populating a default value for “Quote Name”
    3. Return the user to the original opportunity record where they first clicked the button

    So far, I can achieve number 2 and number 3 with the following code:

    https://cs11.salesforce.com/0Q0/e?retURL=%2F006Z00000049jQu&oppid={!Opportunity.Id}&RecordType=012A00000003fBE&ent=Quote&Name=”PQ”&00NA0000004pyaC=1&save=x&saveURL={!Opportunity.Id}

    However, I do not know what to do to also accomplish number 1 at the same time.

    Finally, two follow up questions:

    1. If the above is possible, is also possible to make the tasks dependent on a conditional IF statement that would be built into the button? For example, the button actions would not work if field x is NOT populated?
    2. Assuming that all of the above is possible via a “URL Hack”, would it still be better practice to either:
    a. Create an Onclick Javascript button/Ajax toolkit that would do everything described above
    b. Make this a Visualforce button that calls a custom controller that would do everything described above

    I’m assuming that this “URL hacking”, while potentially possible, is not ideal for future maintenance…..

    Thank you so much for any help!!

    • Ray Dehler says:

      John — you are spot on. This is fully possible with either a javascript button or a visualforce button. Personally, I think that a visualforce button is cleaner, easier to maintain, better for error handling, and faster — but that’s just me.

      • John Braun says:

        Ray,

        Thank you for your response – That’s what I thought you would say.

        However, just for educational purposes, could this be done with a custom button (“url hack”)? And do you know how?

        • Ray Dehler says:

          John — yes, what you described is URL hacking with a custom button. URL hacking is simply setting values on the URL to preload fields on the page layout. VF and JS buttons are indeed custom buttons.

          Do you mean can it be done with a URL custom button instead of a VF custom button? No, it cannot.

          • John Braun says:

            Jay,

            Thanks for the confirmation that it could not be done via a url custom button.

            A question more related to your blog is as follows:

            All of the examples I’ve seen so far with url custom buttons are to create new records. Is it possible to create a url custom button that you could press and simultaneously update multiple fields on an existing record and save?

          • Ray Dehler says:

            John — I haven’t tried it, but I think you can via Rhonda Ross’s suggestion.

  82. Pieter-Jan De Laere says:

    Hi,

    I’m trying to achieve a similar thing with the new event page. I can get it to open with the correct parameters set.

    However, the new event page is opened in a popup from another VF page. My question is: how can I close the popup upon saving/canceling the event; I tried using the retURL and saveURL params with javascript but I don’t get it to work. How could this be done (ideally through calling a custom JS function)?

    thanks

  83. Karen Stock says:

    Longest thread ever :); I think you addressed this above, but the solution wasn’t clear.
    I’m trying to get my custom button to include a step for the user to select the record type. How do I incorporate? It is working currently to pass two fields from the parent object. Thank you!

    /a0t/e?CF00NC0000005GZ8J={!Module_Attachment__c.Name}&CF00NC0000005GZ8J_lkid={!Module_Attachment__c.Id}&CF00NC0000005GZ8O={!Module_Attachment__c.Module__c}&CF00NC0000005GZ8O_lkid={!Module_Attachment__c.ModuleId__c}&retURL=%2F{!Module_Attachment__c.Id}

    • Ray Dehler says:

      First: use a site like this to do some encoding, you’ll want to encode the “&”, “?” and “/”, which are %26, %3F and %2F respectively.

      Next: Find your object Id, navigate to the object in Setup => Create => Objects => Your object, note the URL (e.g. https://na10.salesforce.com/01IF0000001sB3f?setupid=CustomObjects — 01IF0000001sB3f is your object Id).

      Next: Note the URL you find when you click New with multiple record types available to you (e.g. https://na10.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IF0000001sB3f&retURL=%2Fa0S%2Fo&save_new_url=%2Fa0S%2Fe%3FretURL%3D%252Fa0S%252Fo).

      When you select a record type from this page, you’re taken to a URL like this:
      https://na10.salesforce.com/a0S/e?retURL=%2Fa0S%2Fo&RecordType=012F0000000mvM1&ent=01IF0000001sB3f

      RecordType is populated for you, but if you wanted to prepopulate it, that’s possible.
      ent is the object Id located above
      save_new_url from the previous link turns into the URL for this page.

      So the strategy is to convert your URL, url encoded into the save_new_url. I can’t give you the entire URL because I don’t have your object Id, but it’s going to be something like this:

      /setup/ui/recordtypeselect.jsp?ent=YOUR_OBJECT_ID&retURL=%2Fa0t%2Fo&save_new_url=%2Fa0t%2Fe%3FCF00NC0000005GZ8J={!Module_Attachment__c.Name}%26CF00NC0000005GZ8J_lkid={!Module_Attachment__c.Id}%26CF00NC0000005GZ8O={!Module_Attachment__c.Module__c}%26CF00NC0000005GZ8O_lkid={!Module_Attachment__c.ModuleId__c}%26retURL=%252F{!Module_Attachment__c.Id}

      Good luck!

      • Karen Stock says:

        This worked perfectly. Thanks for your detailed instructions and amazingly quick response.

      • Ilyta says:

        Hi Ray,
        The scenerio I have is exactly like Karen’s. I am having a custom object named “Supplement” . It has 2 custom fields Opportunity__c (lookup to opp) and Account__c(lookup to Account) .
        Now I need to create a button on Opportunity named “New Supplement” on click of which I should be able to create new Supplement record , after choosing the record type , and the opportunity name and the related account’s name of the opportunity needs to be auto populated in the fields “Opportunity__c” and “Account__c” respectively.

        When I created this button , everything is passing in the url, but I am not able to populate the custom fields in Supplement.
        The button which i have created :

        /setup/ui/recordtypeselect.jsp?ent=01I60000000Et0I&retURL=%2Fa2l%2Fo&save_new_url=%2Fa2l%2Fe%3FCF00N60000002KOND_lkid={!Opportunity.Account}&CF00N60000002KONr_lkid={!Opportunity.Name}

        where 01I60000000Et0I : Supplement object id
        00N60000002KOND : custom lookup Account field (Account__c)
        opp3_lkid : related Opportunity’s name

        The resultant page url :
        https://cs10.salesforce.com/a2l/e?CF00N60000002KOND_lkid=test666&RecordType=012600000009WMg&ent=01I60000000Et0I&opp3_lkid=test666-tstButton

        where test666 : account name of the related Opportunity’s Account name and test666-tstButton : related Opportunity’s name

        Please advise as of how to auto populate the fields.

        Thanks a lotss!!

        • Ilyta says:

          Hey Ray….

          I got the solution from your suggestion to Karen. So silly of me to overlook it earlier!!
          God bless you for this aw some post…

          Thanks a millions…

  84. Alain Solioz says:

    Great post. I have done my bit of URL hacking, but I learned some new things taday.

    Still, I am wonderieng what exactly does the “what_id” command do?

    Many thanks,
    Alain

    • Ray Dehler says:

      Alain — what_id is only used for Activities (tasks and events), and it corresponds to the “Related To” field. Does that answer your question?

  85. Radmhya says:

    Hello Ray,

    Thanks for the post. I have an issue using this.
    My requirement is to create a new Opportunity button on a related list of an Account which should populate the Opportunity name same as the Account name and also change the Stage(picklist) field to a certain value. I was able to populate the Opportunity name but not the Stage. Could you please help.

    Thank you.

  86. Jeremy says:

    Thanks, couldn’t figure out how to work with a custom field, prepending CF did the trick.
    cheers

  87. Dan says:

    Hi,

    I would like to create a custom button that will change the record type of a lead and convert it to a contact of the same record type all at once. Is there a way to do this? I am pretty new to all of this so any help would be appreciated. Thank you!

  88. Alex says:

    Wow.. all the things I learned! Thanks :)
    I have what seems to be the most trivial problem, but I couldn’t find the solution anywhere.. I have a VF page (searchExistingContact) that serves as an intermediate step before a Contact is created. On that page I have an inputField(Account) that needs to be populated. I tried all types of custom List buttons and nothing works. The URL is created properly, but it doesn’t pre-populate the Account field :(
    Now… this is Standard (Account) field and I’m using standard VF inputField. I tried con4=… and con4_lkid=…, accid=… but none of these worked. Is the field ID different if it’s on a VF page? Is there any other possible ways of pre-populating a standard lookup field on VF page?
    I know.. I must be missing something fundamental, but I’ve been looking for days for an answer. Thanks for any help!

    • Ray Dehler says:

      Alex — standard controller? I’ll need to see the code, please post a pastebin.

  89. Roshan says:

    Hey Ray, your cool article got me rolling for a while but I got stuck. I know this was more or less addressed at very top of the comments section; however, I’m facing an issue here: I want this custom button to throw up an SF page with the standard look up field ‘To’ pre-populated with the right email address. Is being a look up field making it tricky, because using the standard API name p2=test as part of the URL hack isn’t filling the ‘To’ field with “test” when the page is loaded.

    Appreciate any suggestions.

  90. Kelly Hardebeck says:

    Hi,
    Is it possible to set the owner by URL? I’ve created a list button that creates a child record for an opportunity. All the other fields are populating successfully, but I’ve not been able to assign owner. Any ideas?

    /006/e?CF00N50000002qZks={!Opportunity.Name}&CF00N50000002qZks_lkid={!Opportunity.Id}&retURL={!Opportunity.Id}&RecordType=01250000000UMRi&opp3={!Opportunity.Name}+Release&opp11=Released&00N50000001oGKP={!Opportunity.Amount}&opp9={!Today}&00N50000001n1bP={!Opportunity.Site__c}&opp5={!Opportunity.Type}&opp1_lkid={!Opportunity.OwnerId}

    Thanks!!
    Kelly

    • Ray Dehler says:

      Kelly — doesn’t look to be possible using URL hacking, as it’s read only on the page layout. Looks like you can assign owner by workflow, and always fall back on trigger, but not directly via URL hacking on the page layout. I suppose you could have a User lookup, allow it to be URL hack populated, then use a trigger to populate the Owner with that value, that’s one workaround.

  91. John says:

    I am trying to use this on the lead object to populate the company field with the account name using

    /00Q/e?Company=Account+Name

    Has this hack stopped working or am i doing something wrong

    • Ray Dehler says:

      John — just checked, and Company field Id is currently “lea3″ — this works:
      /00Q/e?lea3=Account+Name

  92. Pingback: Salesforce URL Hacking to Prepopulate Fields on a Standard Page Layout | SalesForce.com IQ

  93. Ajay says:

    I have to prepopulate coustom lookup field
    I have to fill value of Parent —> Parent lookup field
    like Contact –> Account—> field which is lookup to Contact
    I am able to pull value in custom field like:
    Account.lookup_field__c which gives name
    but to fill _lkid value i am unable to get ID with Account.lookup_field__r.id
    is there a way to solve this

  94. Eric Willig says:

    I have fields in the Account Object Records that I would like copies to fields in related Opportunity Records. Since we have 2 distinct different business offerings (tagged as EdStart and FireGiants), we have 2 different Account Record Type (with corresponding layouts) and we have to different Opportunity Record Types (with corresponding layouts). I know how to add buttons to each of the Account Record Layouts and it is my goal to add unique buttons to each that will create the appropriate Opportunity record and pre-populate some custom fields.

    I believe I understand the concept of your handy-work (and subject of this page) but am missing something (probably a few somethings).

    Here are the links that I think I need.
    New Opportunity record created from Blood Bank Computer Systems Account Object (which presents a selection of 2 Opportunity formats – EdStart & FireGiants.
    https://na15.salesforce.com/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F001i000000KSCro&save_new_url=%2F006%2Fe%3FretURL%3D%252F001i000000KSCro%26accid%3D001i000000KSCro

    New Opportunity record from the Opportunity tab (object)
    https://na15.salesforce.com/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F006%2Fo&save_new_url=%2F006%2Fe%3FretURL%3D%252F006%252Fo

    New EdStart Opportunity Type record
    https://na15.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=012i0000000W7Qo&ent=Opportunity

    Opportunity field “Number of Teachers”
    https://na15.salesforce.com/00Ni00000081KKl?setupid=OpportunityFields

    Account field “Number of Teachers”
    https://na15.salesforce.com/00Ni00000081846?setupid=AccountFields

    Eric’s MASH UP (that does not appear to work)
    https://na15.salesforce.com/006/e?retURL=%2F006%2Fo&RecordType=012i0000000W7Qo=/00Ni00000081KKl=00Ni00000081846

  95. krishna katve says:

    Is there any way to pre-populate event attendees on salesforce event edit page on custom button click

  96. Shruti says:

    Hi,
    I saw your blog its really helpful, but am confused at one point.

    I have created a Custom button its working fine but it’s no going to Record Type page because am not sure how to include that.I saw that you already discussed above for Record Type but am not able to do it.

    This is my button Link (works fine)

    /a0U/e?CF00NZ0000000sXZW={!VIP__c.Name}&CF00NZ0000000sXZW_lkid={!VIP__c.Id}&Name={!VIP__c.Name}&retURL={!VIP__c.Id}

    But am not getting the Record type selection page, this is the link for Record Type. Please help how do I incorporate the logic for Record types.

    https://cs11.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IZ0000000DhAo&retURL=%2Fa0SZ0000001cphg&save_new_url=%2Fa0U%2Fe%3FCF00NZ0000000sXZW%3Daaa%26CF00NZ0000000sXZW_lkid%3Da0SZ0000001cphg%26retURL%3D%252Fa0SZ0000001cphg

    Thanks,
    Shruti

    • Ray Dehler says:

      I responded via email, and you confirmed this works.

      Simply url encode your url (minus the merge fields) and put it into save_new_url, resulting in this:

      https://cs11.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01IZ0000000DhAo&retURL=%2F{!VIP__c.Id}&save_new_url=%2Fa0U%2Fe%3FCF00NZ0000000sXZW%3D{!VIP__c.Name}%26CF00NZ0000000sXZW_lkid%3D{!VIP__c.Id}%26Name%3D{!VIP__c.Name}%26retURL%3D{!VIP__c.Id}

      You confirmed it works.

      • Christopher says:

        Hi Ray,

        Im experiencing same kind of problem in my project.
        I just want to skip the recordtype selection in the save and new button .
        You mentioned like we can do it through save_new_url parameter.
        I tried but its not working.
        Can u please explain me how it works??

  97. Pingback: How to Redirect Visualforce Page to Standard Pages with Pre-populated fields | Code Jag

  98. Eric Willig says:

    Thanks Ray! Your direction and expertise was so helpful in getting my SF Objects to perform as desired.

    I sincerely appreciate your willingness to share your wealth of knowledge.

    All the best,

    Eric

  99. StephenS says:

    Hi Ray

    I have the following challenge:

    I have a junction object: CLASS_ATTENDANCE which has M-D relationships to SCHEDULED_CLASS and STUDENT. I also have a lookup relationship to CONCESSION_CARD which itself has an M-D relationship to STUDENT

    If I am coming from the CONCESSION_CARD screen, then I know who the student is – since each CONCESSION_CARD must be held by a STUDENT – so I want to pre-populate the STUDENT field.

    If I invoke the New CLASS_ATTENDANCE form from the CONCESSION_CARD related list, then the STUDENT field is greyed out and has “Click lookup icon…” plus search icon. It is not possible to type into the field so I suspect that URL hacking won’t work in this case?

    Can you confirm is there some way to get round this problem?

    Incidentally I understand that the cause of “Click lookup icon” being displayed is because there is a lookup filter on this relationship with STUDENT – however I’ve removed the lookup filter and the behavior hasn’t changed.

    • StephenS says:

      Just found the second lookup filter, disabling this gets rid of the “Click lookup icon” functionality, but it worsens the user experience…

      Would prefer to keep the filter and get URL hacking to work if at all possible!

      • Ray Dehler says:

        Hi Stephen-

        Sorry for the delayed response, but I was able able to confirm URL hacking works with lookup filters. It allows you to specify the controlling lookup and the dependent lookup independently. If you prepopulate the dependent lookup with a field that isn’t valid, it won’t tell you about it until you try and save.

        I’m not sure the issue you’re experiencing, feel free to ping me if you are still experiencing it.

  100. Rabindranath says:

    Hi Ray Dehler,

    Thanks a lot for this Beautiful Article.

    But how can i prepopulate a result of search criteria which is stored in an input text area ,when i click on the clone Button.

    i.e My Search critera is ::: LastName LIKE 7(stored in input textarea)

    when i click on clone then::Field should Have:: Last Name
    Operator should have:: Like
    and value should consists of ::7

    • Ray Dehler says:

      Hi Rabindranath-

      I’m sorry, I don’t think I fully understand what you’re saying, but it sounds like you need some apex to translate the input text area plaintext into some actual logic. This is a pretty specific request, and I don’t know that I could recommend the solution you’re attempting.

  101. Maria says:

    I’m trying to take a custom task layout (with it’s own custom button), and have the account/contact/opp layout populate in the related to field. I can get this to work with a button in the detail page, but from the related list area, no such luck. This is the link that works from the detail area:

    https://na13.salesforce.com/00T/e?what_id={!Account.Id}&retURL=%2F{!Account.Id}&RecordType=012a0000001C7Rt&ent=Task

    Any help is greatly appreciated!

    • Ray Dehler says:

      Hi Maria-

      I don’t see anything wrong with that URL from the detail area. What happens when you click the button? What do you see? Need more info here…

  102. Bradley Delaune says:

    Howdy.
    Anyone have any idea how to use this in a email template? I need to generate the https://{org}/ part of the URL.

    Any help is appreciated!

    • Ray Dehler says:

      It sounds like you want to hardcode this value — at the very least in a custom setting. I don’t see any way to merge this value in an email template.

  103. Ram says:

    I want to add another picklist field along with the record type selection in the UI. When the new button is clicked it should show record type selection page with 2 fields i.e Record type and my custom picklist field. Is this possible?

    • Ray Dehler says:

      Yes, but not with a standard page. It would be a pretty straightforward Visualforce page.

  104. daniel says:

    hey ray – just wanted to say, awesome post!!

  105. brenna says:

    Hello, I created a custom button to be used on a related list on the Opportunity object. The button creates a Project and pulls in the Opportunity Name and Account Name. Here is my URL:

    https://na6.salesforce.com/a0C/e?CF00N80000002c36F={!Opportunity.Name}&CF00N80000002c35q={!Account.Name}&retURL=%01I80000000CMsF

    The problem is that many Opportunities are named the same and I get an error (Multiple items found. Select from drop-down or click icon to refine search) and a pick list to choose from when this happens. Is there not a way to link this to the exact opportunity it was created from?

  106. brenna says:

    Me again… I am creating a case with a specific record type from the opportunity page, I want to auto populate the Account name and Opportunity name inside the created case. However I can only make this work with the custom lookup field for opp name and not the standard field for account name. I don’t know what I am doing wrong and have read every post comment talking about populating standard fields?

    https://na6.salesforce.com/500/e?Account={!Opportunity.Account}&accId={!Opportunity.AccountId}&CF00N800000056W3w={!Opportunity.Name}&CF00N800000056W3w_lkid={!Opportunity.Id}&RecordType=01280000000LwXk&retURL=/{!Case.Id}

  107. Gurunath says:

    how to get the id s dynamically in a link or url

    for example like
    my query is how can i get id dynamically instead of putting manually

  108. Gurunath says:

    How can i get the id dynamically in link or URL ,instead of putting manually

  109. Sakshi says:

    Hello Ray,

    I have custom button on detail page of contact ‘New User’.Want to pass ( standard fields ) first name,last name and email of contact to user ( (standard fields) first name,last name and email .

    Please do help…

    • Ray Dehler says:

      Hi Sakshi-

      This worked for me:
      /005/e?name_firstName=Ray&name_lastName=Dehler&Email=rdehler@gmail.com

      Merge these fields accordingly…

  110. Dan K. says:

    Thanks for all this info. It has really helped me out as I’m a relatively new salesforce admin.
    The only problem I’m facing thus far is populating the Opportunity Close Date as TODAY()+60.
    When I append a URL with just &opp9={!TODAY()}
    what populates in the field is {!TODAY()}
    I checked the field using firebug and confirmed that the function itself is being treated as a text value.
    How do you get around that?

    URL i was testing was:
    https://cs16.salesforce.com/006f0000003dV7Z/e?retURL=%2F006f0000003dV7Z&opp9={!TODAY()}

    Thanks for shortening my learning curve!

  111. Mark Riley says:

    Hi Ray. Great post. really deep knowledge pool. I am stuck with following code on case record
    /500/e?retURL=%2F{!Account.Id}&def_account_id={!Account.Id}&RecordType=012D00000003AlQ&ent=Case
    &cas6=”xxx Hold request”
    &cas14=”xxx Hold Request”
    &cas11=”Account Stakeholder”
    &cas15=”A xxx data check has been requested for” – {!Account.Name}

    The problem is that &cas6 will not populate the picklist value. It stays blank.
    How can I populate the picklist from the custom button?

    • Ray Dehler says:

      Hey Mark — you actually want to URL encode your text. Try:/500/e?retURL=%2F{!Account.Id}&def_account_id={!Account.Id}&RecordType=012D00000003AlQ&ent=Case
      &cas6=xxx+Hold+request
      &cas14=xxx+Hold+Request
      &cas11=Account+Stakeholder
      &cas15=A+xxx+data+check+has+been+requested+for+–+{!Account.Name}

  112. Ray,

    Thank you so much for sharing this!! I’m trying to use this to create two links in the notification emails that are sent to sales reps when they’re assigned a new lead – so that they have to click “YES” to accept the lead or “NO” to decline the lead.

    My attempt at creating this “YES” link:

    Try #1
    PRE
    https:// na3.salesforce.com/{!Lead.Id}/e?{00N50000003Arlw}=Yes&retURL=/{!Lead.Id}
    POST
    https://%20na3.salesforce.com/00Q5000000kqrWJ/e?%7B00N50000003Arlw%7D=Yes&retURL=/00Q5000000kqrWJ

    RESULT: I’m directed to a browser page saying “This webpage is not available.”

    Try #2
    PRE
    https://na3.salesforce.com/{!Lead.Id}/e?retURL=%{!Lead.Id}/&00N50000003Arlw=Yes

    POST
    https://na3.salesforce.com/00Q5000000kqrWJ/e?retURL=%00Q5000000kqrWJ/&00N50000003Arlw=Yes

    RESULT: The correct lead record opens, with the value “Yes” filled in the “Sales Accepted” field. However, when I click Save, I’m redirected to this link: https://na3.salesforce.com/Q5000000kqrWJ/ and get the Salesforce error message that the URL No Longer Exists.

    I also tried the above link with “save=1” added to the end (if possible, I would like the user to be able to skip over the save step) and that just took me directly to the “URL No Longer Exists” page.

    Any help you can offer would be greatly appreciated [PS – I shared the two versions that I think get closest to the correct one, but there were several dozen attempts in between  ]

    Thanks,
    Andrea

    • Ray Dehler says:

      Hi Andrea-

      Try #1: You had a space before na3 which was causing your error message.
      Try #2: Your URL is messed up, you have a random %… I’d start over here.

      I doubt you haven’t fixed this by now, but just in case, feel free to email me :)

  113. Virginie says:

    Hello Ray,

    I have created a lookup relationship from Opportunity to Opportunty it self to have a “Mother” opportunity which have 1 or many opportunities linked (kind of package).

    Then, i added the related list “Package” on the Opportunity but because it’s impossible to rename a standard button, i created a custom button “New Package” (javascript on click as content source)
    But i don’t know how to enter parameters (which code) in the custom button to create a new package linked automatically to the mother opportunity (parameter with opportunity ID).
    Maybe, i can use your method…but does it work with a lookup on the same object ?
    Because for sure, i’m not really good in programming :)
    Thanks a lot

    • Ray Dehler says:

      This is definitely possible, but I can’t provide it for you. You have to follow the steps in this post to get the field Id.

  114. Thaddeus Ward says:

    Do you have any examples of hacks for Event records?
    I would like to prepopulate the fields Subject, Who, What but they seems to be tricky.
    Essentially I want to create an event off of the related list of a custom object where these fields are prepopulated.

  115. Daniel Chapman says:

    I’m trying to insert an email field into the ‘To’ section of a send email button on the opportunity record. However the email doesn’t show up. What am I doing wrong?

    This is the code I’m using:
    location.replace(‘/email/author/emailauthor.jsp?retURL=/{!Opportunity.Id}&p2_lkid=00N8000000569jf&template_id=00X80000001XeEq&p3_lkid={!Opportunity.Id}&p3={!Opportunity.Name}&p5=’)

  116. Nash says:

    Hi Ray,

    This is a really helpful.
    When i try with text field, it worked perfectly fine. When i tried with look up field, i could not get it correct.

    I have a scenario where i have to add default to look up field named “Customer” which should have same value as Account look up field on opportunity.
    And when i click new opportunity from contacts related list, it directs me to record type page not directly to Edit page of opportunity.

    I need some help here.

    Thanks in advance.

    • Ray Dehler says:

      Hi Nash — check out some of the other comments, this is covered exactly.

      With a lookup field from a custom object, you’ll want to ensure you’re setting CF….=(field name) and CF…_lkid=(field id).

      With respect to the record type page, there’s a solution for both
      1) Defaulting a record type, and also
      2) Passing the url hacked variables on once the record type is selected.

  117. Pingback: Querying Custom Object and Field IDs via Tooling API | Andy in the Cloud

  118. Jasper says:

    Hi,

    I’m in need of a custom clone button to clone single QuoteLineItems. Thusfar I came up with this:

    /{!QuoteLineItem.Id}/e?clone=1&retURL={!QuoteLineItem.Id}

    this is unfortunately not doing the trick because when I want to save the cloned line Item I get the following error:
    Error: Invalid Data.
    Review all error messages below to correct your data.
    • You must enter a value (Related field: Price Book Entry)
    • You must enter a value (Related field: Product)

    help much appreciated! ”

    • Jasper says:

      Problem solved!
      Setting the Product field with URL hacking seemed not possible. Ray helped me out perfectly by developing an apex controller that clones the quoteLineItem just the way I wanted. Thanks a lot! This is going to save us a lot of time.

  119. Pingback: Clone a Quote Line Item with an Apex Controller | Cloud Clod

  120. Pingback: Great URL Hack, Meet The Chatter Publisher Action | Wizard & Friends News

  121. Ramakrishnan says:

    Ray,
    Thank you so much for this article!

    I am trying automatically set a checkbox true with this method. The default value is unchecked for this field. However, when I am creating a new record with this method I want this field to be automatically checked.
    I am trying …..&00Ni000000CYbNh=true&…. but to no avail.
    Any other suggestions? Thank you.

  122. Jitender singh says:

    dear sir,

    I have a custom object ‘voucher’ and in case related list.when i click on a case and in it’s related list i override the new standard button of voucher in case related list.

    MY URL is given below:
    https://ap1.salesforce.com/setup/ui/recordtypeselect.jsp?ent=01I90000001JzS3&retURL=%2F{!Case.Id}&save_new_url=%2Fa01%2Fe%3FCF00N90000008H7rX%3D{!Case.CaseNumber}%26CF00N90000008H7rX_lkid%3D{!Case.Id}%26retURL%3D%252F{!Case.Id}%26CF00N90000008HRPJ%3D{!Case.Primary_Store__c}%26CF00N90000008HRPJ_lkid%3D{!Case.Primary_StoreId__c}%26CF00N90000008HKYA%3D{!Case.Contact}%26CF00N90000008HKYA_lkid%3D{!Case.ContactId}

    everything is going fine but i am not able to redirect page via this url back to case after creating voucher.

  123. Cale says:

    Ramakrishnan – You can try setting the checkboxfield=1 instead of =true. I’m not able to test right now, but that’s what I’d try.

  124. Eli Snook says:

    I have a need to create a custom clone button that when clicked updates the Opportunity Stage to “Clone”, reason being, I have tasks automatically generated on “Closed Won” Opportunities and these cloned Opp’s don’t need those tasks generated.

    Here is what I have for my URL button now, it will not update the Stage picklist:
    /{!Opportunity.Id}/e?clone=1&Opp11=Clone

    • Ray Dehler says:

      Eli Snook-

      It looks like the issue you’re running into is case sensitivity in URL parameters. You have Opp11 when it needs to be opp11. I was able to confirm it works with opp11.

  125. Ranjan Saha says:

    Hi ray,
    I have a requirement where whenever a new Task is created and Related To is selected as Case the custom picklist field values related to that Case Number
    are auto populated to the custom picklist fields in the New Task page immediately on selecting a Case number. Please suggest me how to do this.

    • Ray Dehler says:

      Ranjan Saha-

      It sounds like you want some field update to occur on the page after some activity occurs on the page. That’s outside of the scope of what we’re trying to accomplish here, this is simply for prepopulating values upon loading the page only.

      If it needs to be on the page itself, you may have to go with a Visualforce page.

      If it doesn’t need to be on the page, you could always go with a workflow here.

  126. Fredk says:

    Hi,
    thanks for your great post :)

    I have the same question as DCT , but i can’t make it work, i re-ask the same thing .. :
    “Does the URl hacking method work in case of multi-level objects”

    I got A, B C objects , in this hierarchy order
    Lets say fields are A.Id, A.Name, B.Id, B.Name, C.Id, C.Name
    I want to populate C
    C has a lookup on B
    B has a lookup on A

    I create a Button on B To add a new C
    I don’t have any problem to get B info to populate C
    But i cant get A info to populate C
    &MyDestinationField={!B__c.A__c.Id} : KO
    &MyDestinationField={!B__r.A__r.Id} : KO
    &MyDestinationField={!B__c.A__r.Id} : KO
    &MyDestinationField={!B__r.A__c.Id} : KO
    &MyDestinationField={!B__c.A__c} : KO
    &MyDestinationField={!B__r.A__r} : KO

    the interface accept the
    &MyDestinationField={!A__c.Id} : but no value has been passed in the URL

    It seems not possible , or i miss something ?

    Thanks for your reply

    • Ray Dehler says:

      One option would be to just have a formula field on the B object which pulls in the field you need and could be used as a merge field for C…

      • Fredk says:

        Thanks for your fast reply :)
        Yes, i know that technic, but it will pollute my data schema with “unecessary fields” …
        So we could say, no way to navigate trough lookup fields, fields must be at the same “data level” : so sad :(

        Will I have the same problems in Javascript, i guess ?
        Another alternative will be to do a S-control ?

        I will certainly be lazy and will do your “formula solution” :/
        Thanks a lot for your commitment
        Cheers

        • Ray Dehler says:

          Yeah sorry, url hacking doesn’t work too well when we talk about complex scenarios with multiple levels of lookups.

  127. Pingback: Salesforce URL Hacking basics with retURL, saveURL and cancelURL | Cloud Clod

  128. Lawrence says:

    Hi,

    I am creating a button to pre-populate an email address from contact onto the asset . But it does not seem to working. Please can you see where am I making the mistake. My ur is below.

    https://cs8.salesforce.com/02i/e?retURL=%2F001L000000Qwyg8&acc_id=001L000000Qwyg8
    &00NL0000002zLFW(email id on asset)= 00NL0000002zMP3(email id on contact)

  129. Lawrence says:

    Further the contact is not related to the asset . The asset is only related to the account. and the contact obviously to the account. Please let me know where am I going wrong.

  130. kelly says:

    I need create a new lead based on case info fill into lead,the code as next,but it did not work to auto fill in description from case to lead:
    /00Q/e?Description={!JSENCODE(Case.Description)}&Email={!Case.SuppliedEmail}&LeadSource=Email

    does anyone can help me?

    • Ray Dehler says:

      It’s because the field’s name isn’t Description, it’s lea17. This works:
      /00Q/e?lea17={!JSENCODE(Case.Description)}&Email={!Case.SuppliedEmail}&LeadSource=Email

  131. sridhar says:

    Hi,

    This is a Button code (Detail page Button). It is working fine but when I am using this button in Salesforce Console, I am getting the following error message:

    Unable to Access Page
    The value of the “id” parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

    Submit For Processing Button Code:

    /500/e?retURL =%2F500%2Fo
    &RecordType=”012700000001OPD”
    &CF00N70000002G4Bf_lkid={!URLENCODE(Opportunity.Id)}
    &CF00N70000002G4Bf={!URLENCODE(Opportunity.Name)}
    &cas7= “New Approval Request”
    &cas5= “Submitted for Approval”
    &cas8= “High”
    &cas14= “Submit Sale:{!URLENCODE(Opportunity.Name)}”
    &cas11= “Internal”
    &save=Submit
    &cancelURL=%2F{!URLENCODE(Opportunity.Id)}&ent=Case

    Any suggestions on this?

    Thanks,
    Sridhar.

  132. Riaz Muhammad khan says:

    really nice, but i am confused with ids in url u r passing, passing values to two fields and id’s are more than two in url, confusing me, have you login account i want to check it(id’s)

  133. Shillem Volpato says:

    Tremendous post. I tried to go through the article and the comments but it seems I haven’t been able to find an answer to my current problem using this technique.

    I created a new task button – with follow-up activity – that prepopulates the RecordTypeId field for both. It works fine.
    But I noticed that if I miss to fill out required fields and press save I’m told I can’t continue until I fill out those fields, obviously. At that point though, my nice query string gets reset and I have lost all the prepopulation information coming with it – the most annoying is the missing record type info on the follow-up section which reverts to the default record type id.

    The only solution is to click on the browser back button and continue from there… not really intuitive. Any ideas or it’s a dead end for this kind of hack?

  134. Ray Dehler says:

    I’m closing comments for this post. Might I suggest anyone who has questions post them to http://salesforce.stackexchange.com/ with the tag “url hacking”.

Comments are closed.