Salesforce URL Hacking for Lightning – Tutorial

Share this article...

You may remember the popular Salesforce Classic URL Hacking tutorial that Ben wrote back in 2015. You may also remember that Lightning Experience didn’t initially support URL hacking, which was replaced with Custom Actions.

With all that said, I’m writing right now to tell you that Salesforce has changed its minds once again on this topic – but it’s good news! The Spring ’20 release (February) brought with it many updates and new features, as well as the re-release of a much-loved feature from Salesforce Classic – the ability to hack URLs is a power that Admins can harness once again even in Lightning Experience!

What is a Salesforce URL Hack?

Simply put, a URL Hack is a custom-built button that creates a new record, and presets some default values using static or dynamic fields based on the record you’re currently on.

For example, if I had an Account record open on my screen and I clicked my custom ‘New Contact’ button, I could prefill some of the Contact’s information based on that of the parent Account (Account Id, Phone, and Address are popular examples).

URL Hacks are a handy way of creating records with specific fields populated automatically, rather than setting a field-level default across the board (that would be applied to every new record). This method also allows you to utilise the standard Page Layout as opposed to a custom solution.

Lightning URL Hacks vs. Actions and Classic URL Hacks

How are the new URL Hacks different to the old ones, or Custom Actions? The old URL Hacks only function in Salesforce Classic, and had to be replaced by Custom Actions when you transitioned to the Lightning Experience.

The old URL Hacks also used the field Ids (yuck) rather than API names, which are much easier to read if you ever need to make a change to your existing button.

Are there any restrictions?

Unfortunately, there are some fairly tight restrictions that apply to the new URL Hacks. You won’t be able to use these buttons inside of a Community or in the Salesforce Mobile App. They also won’t work outside of Lightning.

How Can I Build a URL Hack?

To be able to use a Custom Button to create records, you’ll need to:

  1. Create the button
  2. Add the button to your layout (so you can test it)
  3. Define values for the newly created record’s fields – whether they’re static values, or dynamic based on the record. More on that coming now.

I’m going to lead you through an example. We’re going to create a Contact record from an Account and populate some default fields. I want the button to be available from the Account (on a Business Account Page Layout), and I want it to prepopulate the Owner, Lead Source, and Mailing Address fields, as well as relate the Contact to the Account.

Step 1: Create the Custom Button

To do this, we need to navigate to our Master Object in Object Manager – this is the object that we’re going to be placing our button on, so in our example, the Account is the Master Object.

When going through the steps to create the button, make sure to select the ‘Detail Page Button’ value in the Display Type picklist; this ensures it’s available as a regular button, similar to a Custom Action.

Step 2: Add in the URL

Next, we’re going to add in our URL. Below is the completed code example.

/lightning/o/Contact/new?defaultFieldValues=

OwnerId={!Account.OwnerId}, AccountId={!Account.Id},

MailingStreet={!Account.ShippingStreet},

MailingCity={!Account.ShippingCity},

MailingState={!Account.ShippingState},

MailingPostalCode={!Account.ShippingPostalCode},

MailingCountry={!Account.ShippingCountry},

LeadSource=Custom+Contact+Button

What does that all mean? Let’s go through it!

To learn the API Field Name of a field on the resultant record (the new record you’re creating, not the record you’re pressing the button from), navigate to that object in Object Manager and refer to the Field Name column; that’s a general rule, but there are a few exceptions to this (eg. standard Address fields).

You can use the same method to dynamically set the field values if you know them, or you can use the Insert Field feature on the New Custom Button page.

Let’s look at the first line:

/lightning/o/Contact/new?defaultFieldValues=

What we’re doing here is specifying the object that we want to create – Contact – and preparing to populate the ‘defaultFieldValues’ parameter with static and dynamic values (each field will be comma-separated and part of the master URL parameter).

Let’s take a look at the next two lines now:

OwnerId={!Account.OwnerId}, AccountId={!Account.Id},

What we’re doing here, is specifying that the Owner of the Account also be the Owner of the newly created Contact record. We’re also ensuring that the Contact is related to the existing Account. Once again, you can use the Insert Field to insert the master object (in this case Account) merge field if you’re unsure.

We’re setting the Contact’s Mailing Address field values across the next five lines:

MailingStreet={!Account.ShippingStreet},

MailingCity={!Account.ShippingCity},

MailingState={!Account.ShippingState},

MailingPostalCode={!Account.ShippingPostalCode},

MailingCountry={!Account.ShippingCountry}

The ‘Field Name’ column on the Contact object doesn’t split standard Address fields unfortunately. You can read more about that on this Salesforce Developer article, but generally, I find that the Street, City, State, PostalCode, and Country fields are the ones I use the most (append whatever prefix is required, in this case Mailing or Shipping).

Finally, the last line sets a LeadSource value so we know that the Contact was created using the button:

LeadSource=Custom+Lead+Button

Two things that you’ll notice are different here:

  • the value we’re passing is static, not based on a field value from the Account,
  • and there’s no comma at the end because this is the last line.

! Note: A critical missing piece!

What I’m about to tell you is not mentioned in the release notes. The release notes show the example with returns/line breaks in it, to make it easier to read your URL in the button. You will need to REMOVE your line breaks for the code to work.

So, instead of seeing:

/lightning/o/Contact/new?defaultFieldValues=

OwnerId={!Account.OwnerId}, AccountId={!Account.Id},

MailingStreet={!Account.ShippingStreet},

MailingCity={!Account.ShippingCity},

MailingState={!Account.ShippingState},

MailingPostalCode={!Account.ShippingPostalCode},

MailingCountry={!Account.ShippingCountry},

LeadSource=Custom+Contact+Button

You’ll need to remove your returns. You should then see:

/lightning/o/Contact/new?defaultFieldValues=OwnerId={!

Account.OwnerId},AccountId={!Account.Id},

MailingStreet={! Account.ShippingStreet},

MailingCity={! Account.ShippingCity},

MailingState={! Account.ShippingState},

MailingPostalCode={! Account.ShippingPostalCode},

MailingCountry={! Account.ShippingCountry},

LeadSource=Custom+Contact+Button

I don’t want to talk about how much troubleshooting it took me to realise this mistake, but instead I thought I’d make a strong mention of it so you don’t run into the same issues!

Step 3: Testing

Once we’re ready to begin testing, we can save the button. We still need to add it to our Page Layout before we can use it, so find the relevant Business Account Page Layout and edit it. If

you’ve followed these steps correctly, you should be able to see your button under Buttons and also again under Mobile & Lightning Actions sections.

We’re going to add it from the Mobile & Lightning Actions into the Salesforce Mobile and Lightning Experience Actions section (you may need to override this section before you can add it in). Don’t forget to save your Page Layout when you’re done.

Fantastic, now it’s time to test it! Navigate to a Business Account record that uses the Page Layout you just updated and click the button.

This is our creatively-named Account, ABC Company.

You will now see a full page layout for your new Contact record, with the profiled values you defined in your custom button.

If you don’t see the values you set and instead receive an error on saving, you’ll need to double check your carriage returns as this is likely causing the issue.

Important Things to Remember

  • URL HATES carriage returns, and won’t function correctly. They must be removed from your button.
  • URL HATES spaces: if you’re setting a static value, use a plus (+) instead of a space, and if you’re dynamically populating don’t forget to add {!URLENCODE()} to your button to have it formatted correctly.
  • Don’t forget to set the button’s Display Type pick list value to Detail Page Button so it shows up correctly, and add it to the Page Layout using the Mobile & Lightning Actions button rather than the Buttons button.
  • If you’re receiving an error upon save that says there’s no access on a particular field, check that your carriage returns are removed. I’m mentioning this again because it caused me quite a bit of grief!
  • Don’t forget, this doesn’t work on mobile. Hopefully we’ll see this updated in the future.

102 thoughts on “Salesforce URL Hacking for Lightning – Tutorial

  1. Michelle Diotalevi

    Reply

    Thank you for this post, Tim. Calling out the critical missing piece saved me! I do have two questions and am hoping you might be able to assist. 1) Two of the fields I am trying to dynamically set are dependent and are returning blank values when I test. Is there a workaround? 2) One of the fields I am trying to dynamically set is a Date Data Type. When I add it to my URL and test, it returns the following error message: Unable to parse Record’s field value[s]. Any ideas? Thanks again!

    1. Hey there Michelle, thanks for reading! I’m glad to hear calling that out helped you – I’m not going to say how long I spent trying to get it working before realising it for myself…
      With regards to your issue with the field dependencies, I’ve been able to replicate the issue and have played around for a few hours to no avail. I’m able to have the Master field populated, but not the dependent unfortunately. It looks like this is a restriction for some reason.
      Regarding your date field, I’m receiving the same issue when I’m using the {!DATE()} function, HOWEVER I have a solution – if I use the same format that I’d use in Data Loader, I can successfully set the date. See this article, and that section of my button code below: https://success.salesforce.com/answers?id=90630000000gsd8AAA

      Date__c=2020-01-01T00:00:00
      Original format: YYYY-MM-DDThh:mm:ss

    1. Hey Rohit, thanks for reading! I was able to do a bit of reading and found out how this can be done. If you’re looking to enforce the Record Type Selection page at the beginning, you can add useRecordTypeCheck to the beginning of the button, like so:

      /lightning/o/Custom__c/new?useRecordTypeCheck=1&defaultFieldValues=OwnerId={!Account.OwnerId}

      Or, if you want to set the Record Type in the URL code, use recordTypeId and populate the Id of the RecordType you want to use, as below:

      /lightning/o/Custom__c/new?recordTypeId=0127F000000NVxPQAW&defaultFieldValues=OwnerId={!Account.OwnerId}

      1. So glad I found this comment as Salesforce says it’s not possible to go directly to a specific record type!

      2. Hey Tim,
        Yes, you can pass recordTypeId in the URL code but the name on the header of lightning page beside “New Object Name:” is always taken from default record type assigned to profile irrespective of what you are passing in RecordTypeId
        Do you know any solution for it?

        1. Hi Kapil,
          It used to show the default record type for me too but I fixed it by moving recordTypeId parameter before defaultFieldValues parameter just like in the example provided by Tim. Thanks Tim for this article. It helped a lot.

  2. Here is one test it somewhat fails on. Try hitting Cancel on the pop up box. It will not take you back to the previous page. A blank page is displayed instead, and the user will have to click the Back button once or twice to return to the previous page.

    I have been in contact with SF support and they are supposed to provide a fix on the next release (hopefully in Spring 20). But in the meantime here is a workaround that I found. Hope it helps.

    https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XqtCQAS

    1. Hi Jun,

      I’ve not had this issue before, are you implementing your button differently to how I outlined above? For me, it loads a popup modal and when I close it, the original record is displayed.

      1. Hi Tim,
        The only different thing I’m doing is that I’m using it as a List Button so that I can place my custom button in a related list. I know your article specifies that the ‘Detail Page Button’ option must be used. However, I believe that SF should support the other ways a custom button can be used, i.e., namely as a List Button. This is the reason why I pushed SF support for a fix. And like I said, they’ve indicated that it is coming in Summer 20 (sorry for the typo in my earlier post where I said Spring 20), but I don’t see it in the release notes yet. So I’m hoping they can deliver.

      2. Hi TIm,
        I also faced the same issue while treating url hacked button as list button. So I added something extra with the url and it worked, try using ‘&backgroundContext=/lightning/r/Contact/{!Contact.Id}/view’, I also tried to redirec to reltead tab instead of details tab so I tried &navigationLocation=RELATED_LIST, it worked for standard object but got busted in custom object

        1. Hi,

          can u please show the whole URL?
          where did u put the ‘&backgroundContext=/lightning/r/Contact/{!Contact.Id}/view?

          thanks

    1. Hey there, Peter!
      I’ll reference and simplify the example in the release notes (https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_general_lex_navigate_to_record_dfv.htm):

      /lightning/o/Account/new?defaultFieldValues=Name={!URLENCODE(Account.Name)},OwnerId={!Account.OwnerId},AccountNumber={!Account.AccountNumber}

      Essentially, place a field value within the {!URLENCODE()} to have it applied. To learn more about the URLENCODE function, have a look at Salesforce’s documentation here: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/urlencode.htm

    1. Hi Priyankar, Thanks for reading!

      You’re right – unfortunately, it seems this functionality doesn’t work on mobile… I have done some digging and haven’t been able to find a reason why as yet, and have noticed others running into the same issue. Fingers crossed this is fixed in the near future!

  3. How can I use this to edit an existing record? For e.g. I want to update contact fields from a case?

    1. Hi Yogesh, Thanks for reading and I hope you were able to find some value from the article.

      What’s your intent behind wanting to edit using this functionality? The biggest benefit using this functionality is defaulting fields on NEW records, which I don’t believe you’d be able to do on an existing record (as the values are already set). There may be another solution I could suggest?

      Thanks!

  4. Julianne DeGeorge

    Reply

    Great post Tim! Do you (or anyone out there) know how to set the contact as a contact role with a custom ‘New Opportunity’ button that would be on the contact record? It appears that with Classic URL hacking it was ‘conid’ but that does not work in Lightning. Any advice would be great! Thank you!

  5. I am facing issues with ,

    1) lookup fields. Value is not populating.

    I want to show same field value to be populated on new opportunity.

    Primary_Contact__c is lookup field on opportunity.

    /lightning/o/Opportunity/new?defaultFieldValues=Primary_Contact__c = {!(Opportunity.Primary_Contact__c)}

    I also tried with !URLENCODE() but still getting blank field

    2) Date field is showing blank

    First_Closed_Date__c = {!Opportunity.First_Closed_Date__c}

    I tried

    First_Closed_Date__c = {!TEXT(Opportunity.First_Closed_Date__c)} , used TEXT, still its not working.

    3) Facing same issue for picklist field. Getting blank field.

    I

    1. I ran into that first issue today, but I got it to work by creating a formula field to pull the ID for the record I wanted to pre-set, then used the formula field instead of the original lookup field.

      For your example, it would look like this:

      1) Create a formula field Primary_Contact_ID__c to pull the ID for that Primary_Contact__c field.

      2) Update your URL with this:
      Primary_Contact__c = {!(Opportunity.Primary_Contact_ID__c)}

  6. Hi Tim,

    Thank you for this interesting post.

    I was trying to apply the above on Opportunity and create a Quote with specific recordtype from the Opp. But seems it’s not recognising the recordtype:

    /lightning/o/Quote/new?RecordTypeId=01236000000C7KAAA0&defaultFieldValues=ExpirationDate={!TEXT(TODAY()+15)},AccountId={!URLENCODE(Opportunity.AccountId)},OpportunityId={!URLENCODE(Opportunity.Id)}

    I’ve tried recordTypeID and RecordTypeID and both are not applying the correct id

    Any idea?

  7. Hi Ramy,

    recordTypeId Attribute name is case sensitive, It must be camel Case, so you have to use recordTypeId.
    I.e /lightning/o/Quote/new?recordTypeId=01236000000C&defaultFieldValues=ExpirationDate={!TEXT(TODAY()+15)}

    This must worked.

  8. Can we use this clone a record also? I mean for same object, if I add this button on detail page, it should create a new records with default values.

    1. Yes, in my case this worked:
      /lightning/o/Opportunity/new?defaultFieldValues=Industry__c={!Opportunity.Industry__c},OwnerId={!Opportunity.OwnerId},AccountId={!Opportunity.AccountId},Name={!Opportunity.Name},Project_Type__c={!Opportunity.Project_Type__c},Application__c={!Opportunity.Application__c},Sub_Application__c={!Opportunity.Sub_Application__c},LeadSource={!Opportunity.LeadSource},Secondary_Lead_Source__c={!Opportunity.Secondary_Lead_Source__c}

  9. Hi Tom, great article, it helped a lot.

    I am running in an Issue, regarding blank custom Lookups.

    e.g.

    Custom_Lookup__c={!Account.Custom_Lookup__c}

    If this Lookup on the original Account is blank, an error uoccurs. I tried all combinations of ISBLANK, ISNULL, etc but did not found a solution besides creating a support field, which stores the ID or a blank value. But this is really bad design. Any advice on this?

    Many thanks in advance!
    Dennis

    1. I’m dealing with the same issue. I tried doing an IF statement to check if the field is blank first but it’s still not working. Hopefully someone knows!

    2. For Custom Object (My_Custom_Object__c) and lookup field (Lookup_Field__c) the syntax {!Custom_Object__c.Lookup_FieldId__c} seems to work okay for me.

      I noticed the similarities with the merge field format from email templates so pulled across what the previewer gave me and it seemed to do the trick. Best of luck!

  10. Pascaline Spengler

    Reply

    Excellent Post, thank you for that !

    I had to do some research myself on the return/cancel URL myself because I haven’t used it for a while – but will again now that it’s finally supported in LEX – so I thought it might be of interest to share it with the community, maybe it will save time for some fellow Admins 😉

    to return to the “start” Record (Buttons on Record Page)
    # after “Save” => &retURL={!Object.Id}
    # after “Cancel” => &cancelURL=/{!Object.Id}

    to return to the Object ListView (i.e. for Custom “New Object” Buttons)
    # after “Save” => by default opens the record Page (which is most likely what you want anyway)
    # after “Cancel”=> &backgroundContext=%2Flightning%2Fo%2FObject%2Flist?filterName=Recent
    !! Note here, “Recent” means the ListView as you selected it last time, not the standard “Recently Viewed”

    1. Hello Spengler,

      I need help on cancel button , I created a custom lightning button with default values, of a user is while creating a record chooses cancel it will redirect to blank page..how do
      I put the cancel url also in my custom new button??

  11. Excellent Post, thank you very much! I refer to the post from Julianne. Do you (or anyone out there) know how to set the contact as a contact role with a custom ‘New Opportunity’ button that would be on the contact record? It appears that with Classic URL hacking it was ‘conid’ but that does not work in Lightning. Any advice would be great! Thank you!

    1. @Benjamin, for me, ContactId={!Opportunity.ContactId} worked for creating a ContactRole marked a Primary

    1. Matthew, you don´t need a URL to do that. Any quick Action can pre populate the Template and any fields.
      Maybe, if you explain the use case a little, we might be able to help…

      1. @Dennis Leyens, I am working off a custom object called, Project.

        I created a Send Email Quick Action, called Email Report.
        I set the Predefined Field Value for the “To Recipients” field to the Id of the contact populated in a contact lookup field on the Project page layout.

        The quick action isn’t a button up in the Highlights panel. When I click on the Email link in the Activity History Related List. It launches the “Email Report” quick action but the To field isn’t populated.

        When I changed the Default Activities View to the Activity Timeline view, I get a standard Email tab and a tab for my Email Report quick action. When I create an email here, the To field populates.

        https://help.salesforce.com/articleView?id=customize_records_record_activities_view.htm

        I don’t get why email is so tricky in Lightning. The whole reason I’m doing this is because when our users try to manually populate the To field with a contact, it brings up every instance of that contact without saying which account they are tied to. (I know the contact duplicates is another argument altogether).

  12. Muhammad Jawwad

    Reply

    Multi Picklist having a % sign in value not passing through defaultFieldValues? any suggesstion?

  13. Hi Tim,

    Thank you for the detailed article, it is really helpful. Just wanted to check if there is a way to have some validations introduced(like we used to do in classic) before the users are redirected to the URL?

  14. Great post! Has anyone been able to pull in lookup values? I am having the same issue as another post. In my situation I am trying to pull in the opportunity to a custom lookup on the case object.

    1. Gaylene,

      I resolve mine by creating a formula(text) field for the Id. Then using that Id. I haven’t been able to populate a lookup using another lookup.

      Example I am on the opportunity trying to create and prepopulate a lookup on the Quote with the lookup on the opportunity, but I had to use the formula Id.

      1. (1) I was able to populate the opp id in a custom lookup on Case with this syntax: Related_Opportunity__c={!Opportunity.Id}.
        (2) I was able to populate a lookup on Case using a lookup on the source Opportunity with this syntax: Related_sampleObject__c={!Opportunity.Related_sampleObjectId__c}, where the API name of the lookup field on both Opp and Case is “Related_sampleObject__c”.

        1. I am still having issues. It works when I am logged in as myself, but then if i login as another user it dosn’t work.

  15. I use URL hack to generate an email using a formula field with the email template ID.. It’s pretty neat in classic and haven’t been able to find an alternative in Lightning. Any ideas? This is what I use in classic:

    /_ui/core/email/author/EmailAuthor?p2_lkid={!Enrolment_Form__c.Student_NameId__c }&p3_lkid={!Enrolment_Form__c.Id}&template_id={!Enrolment_Form__c.AUS_DOM_Offer_Template_ID__c}&p24={!Enrolment_Form__c.Student_Email__c}&new_template=true&[email protected]&retURL={!Enrolment_Form__c.Id}

  16. This is giving me an error saying “Error: Field ab__c is a picklist field. Picklist fields are only supported in certain functions.” Any ideas?

  17. Great post. We are still using classic but this pops up a lighting window with all my default values when done as a sys admin. However, when done as a standard user none of the field values are being pre-populated. Any ideas why this might happen?

    Also, I have this button on an Opp, do you know how to force the product selection page to display after the Opp is created?

    Thanks.
    Keith

  18. Hi Tim,

    I’m actually having an issue when trying to “save” the record (pressing “Cancel” on the record is fine) after pressing the custom URL button.

    Here’s a video example:
    https://www.screencast.com/t/hrOkuHx4

    Let me give you some background:

    As we’re transitioning to Lightning, the business is requiring Lead information to be populated to activities (which can’t be done using Actions). I’ve created a URL hack for “New Task” which displays near the buttons on the Lead lightning page. Pressing the “New Task” button (and cancelling) is working fine, but when I try to “save” the Task record, it re-directs me to the Task page, despite having &retURL at the end of my hyperlink.

    I’ve tried every possible solution I can think of, but this issue still persists. Can somebody please help me if they know how to return to the record the button was pressed on? (in my case, Lead)

    My URL example:
    /lightning/o/Task/new?defaultFieldValues=
    {!IF(ISBLANK(Lead.AccountId__c),”,’WhatId=’&Lead.AccountId__c)},
    {!IF(ISBLANK(Lead.Primary_ContactId__c),’WhoId=’&Lead.Id,’WhoId=’&Lead.Primary_ContactId__c)},
    Lead_Lookup__c={!Lead.Id}
    &retURL=%2F{!Lead.Id},
    backgroundContext=%2Flightning%2Fr%2FLead%2F{!Lead.Id}%2Fview

    Can somebody help me? That would be amazing

  19. Tim, I’ve created a new Button and also a new Action, but they are not available on the Page Layout. How do I fix this?

    1. Fixed it! My New Action was available on the Page Layouts, but did not perform as desired. I wanted the newly created Event to display in edit mode. I did manage to get the New Button available on the Page Layouts.I had incorrectly selected the Display Type as ‘Detail Page Link’. Changing this to ‘Detail Page Button’ made it work.

  20. Hello Tim and Everyone,
    Does URL hacking works with custom fields on Case or is there any limitations?
    I have been working on it, but running into issues,

    USECASE:
    I need to pre-populate child case fields from parent case and select record type,
    /lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=
    CaseNumber={!Case.CaseNumber},
    ParentId={!Case.ParentId},
    abc_first_name={!Case.parent_First_Name__c}

    abc_first_name= first name on child case
    parent_First_Name__c = first name of paren case

    any help is greatly appreciated

  21. Hi Tim,
    Thanks for great post, its helping me in my use case, however I’m facing two issues,
    1.I’m unable to pre-populate dependent picklist value, is there any restrictions and workaround?
    2.I’m unable to pre-populate date and look-up fields,

    Can you provide work around for these!

    Thanks

  22. Does anyone have a url hack to pass in a unique identifier and load the Salesforce record page that has that id (not record id but a custom unique field).

  23. Hi Everyone,

    I’m trying to create a button that will create a new case of specific record type, and I only want certain fields to show when creating the new case. Similar to a quick action. Is this even possible? I’m trying to use a button instead of the quick action because I have case feeds enabled.

  24. Thanks Tim! Looks like you need to update this post to replace commas with ampersand, since my buttons stopped working until I replaced the commas with ampersand in the URL

  25. Hi Folks

    This functionality is not working in my Sandboxes after the upgrade to Winter’21 this weekend. Any Idea?
    Basically, last friday, everything works well. This Monday doesn’t work anymore.

    Any Idea?

    Thanks!

  26. I am in need of a URL Hack that will not only clone an existing Quote (this works: /lightning/o/Quote/new?defaultFieldValues=OpportunityId={!Quote.Opportunity_ID__c}), but will also clone associated quote line items. The simplest URL Hack in Classic would do both, but this longer URL for Lightning does not. I would so appreciate any help!

  27. Yes the spaces were creating a big issue as I was populating the case description dynamically from the parent case, The error is also misleading

    !URLENCODE()} came to rescue, thank you

  28. I had the same problem with dependent picklist values, but I noticed today it’s working now. It looks like it got fixed at some point after September (maybe the Winter ’21 release?).

  29. Hi All,
    Thank you for this solution, we used button hacks like mad in Classic and are just trying to migrate our teams over to Lightning. I am part way there with making my URL Hack code below work, but I need your help. The code is essentially opening up a new case by pulling data from an Oppty record into a support case. The button is successfully opening a new case page layout for the proper case record type AND it is properly pulling in the SUBJECT field and the variable Opportunity Name as specified in the URL code, however it seems to stop there. It is not pulling in any of the other variable information into my case. I checked for spaces, removed all the “returns”, etc. Am at a loss – please help! :-/

    Here is a sample of my code:
    /lightning/o/Case/new?recordTypeId=012380000001uSM&defaultFieldValues=Subject=Sales Support Requested for +{!Opportunity.Name}&OpportunityId__c={!Opportunity.Id}&Oppty_Amount__c={!Opportunity.Amount}&Oppty_Tier__c={!Opportunity.Edition__c}

  30. Angela Mullen-Smith

    Reply

    I am trying to create a url for creating a Log a call task – I need it to flagged as a Log a call with the icon – Log a call and success message – you have logged a call

    This will only log a task

    I have tried adding in subject=call
    o/Task/new?defaultFieldValues=Cirrus_Call_Log_ID__c=757149437,IVR_Option__c=,Date_of_Call__c=2021-1-21,Start_Time_of_Call__c=12:54,WhatId=0011x000013Z8gZAAS,WhoId=0031x000011CA3XAAW&count=1&nooverride=1&navigationLocation=LIST_VIEW&backgroundContext=%2Flightning%2Fr%2FContact%2F0031x000011CA3XAAW%2Fview

  31. Angela Mullen-Smith

    Reply

    Hi
    I have tried that but because replaces the O for object with an r – it does allow it to be used

  32. I’m trying to make a custom button that will add a Quote Line Item with specific values prepopulated. My button code is:

    Button or Link URL /lightning/o/QuoteLineItem/new?defaultFieldValues=
    QuoteName={!URLENCODE(Quote.Name)},
    QuoteID={!Quote.Id},
    Is_Option__c=true

    These default values work, but the dlg that pops up does allow me to select a Product for the line item. I’m guessing it is related to pricebook settings. Does anyone have any suggestions?

    My goal is to replicate the functionality of the native “Add Product” button for Quote Line Items, but adding in a few preconfigured fields. I’m open to other suggestions if there is a better way.

  33. Can we add condition? Example depending on the checkbox value is checked or not then only create the new record

  34. Has anybody else found the issue that you cannot use backgroundcontext and defaultFieldValues parameters in the same URL?
    It seems like as soon as you add in backgroundcontext it removes the defaultFieldValues from the string.

  35. Hi Jack, I was having the same problem and have finally figured out the correct syntax and it works great in Lightning. This is for a button on the related list to my custom Opportunity Object (both are custom objects):

    1. From the Opportunity, we click on the Opportunity Contact Role related link/list
    2. We click the Custom button. Below is the code. This code keeps us on the related list view. If we Save, it takes us to the newly created Opportunity Contact Role. If we “Cancel”, it returns us to the Opportunity Contact Role related list.

    {!URLFOR(‘/lightning/o/Opportunity_Contact_Role__c/new?defaultFieldValues=Opportunity__c=’&Opportunity__c.Id+’&backgroundContext=%2Flightning%2Fr%2FOpportunity_Contact_Role__c%2F’&Opportunity__c.Id+’%2Frelated%2FOpportunity_Contact_Roles__r%2Fview’)}

    Hopes this helps others. I was having trouble finding an example that 1) provided the correct syntax and where to add the ” ‘ ” marks and 2) Kept us on the related list.

    Best, Lee Anne

  36. Figured it out! We too, had a related list and a custom button to add a new Opportunity Contact Role. Once we switched to lightning the default value (the opportunity this new Contact was related to) and the Cancel button were no longer working as expected. Here’s the syntax I used to fix it to work in lighting. ** Please note that our Opportunity object and it’s related Opportunity Contact Roles object are both custom objects.

    {!URLFOR(‘/lightning/o/Opportunity_Contact_Role__c/new?defaultFieldValues=Opportunity__c=’&Opportunity__c.Id+’&backgroundContext=%2Flightning%2Fr%2FOpportunity_Contact_Role__c%2F’&Opportunity__c.Id+’%2Frelated%2FOpportunity_Contact_Roles__r%2Fview’)}

    Now, when we’re on the related Opportunity Contact Roles list and we click the Add Additional Contact button, the Parent Opportunity is there by default and if we hit cancel, it’s no longer blank. 🙂

  37. Hi Tim, Thank you for this! I created a button to create a new quote from an opportunity. It works great as admin but it doesn’t work as a user in a custom profile I created. I am getting a pretty vague error. Here is my code for the button. Any ideas what would cause this. The user has full object permission to opp, quote and contact.

    /lightning/o/Quote/new?defaultFieldValues=
    Name={!Opportunity.Name},
    ExpirationDate={!TEXT(TODAY() + 24)},
    OpportunityId={!Opportunity.Id},
    Phone={!Contact.Phone},
    Email={!Contact.Email},
    ContactId={!Contact.Id}

    The error is

    Looks like there’s a problem.

    Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details.
    Error ID: 1382585955-15298 (-388881258)

  38. Hi Tim,

    Great article. thank you so much for writing it.

    Do you know how you would write this so that the button would work in classic and lightning?

    Thanks!

    1. I figured it out, posting in case others still need classic and lightning.Hopefully our company can be rid of classic soon.

      {!IF($User.UIThemeDisplayed=”Theme4d”,
      URLFOR(‘/lightning/o/Civil_Bid_Book__c/new?useRecordTypeCheck=1&defaultFieldValues=Opportunity__c=’+Opportunity.Id+’,Bid_Book_Amount__c=’+TEXT(Opportunity.Amount)+’,Bid_Submission__c=’+TEXT(Opportunity.Bid_Submission__c)+’&backgroundContext=%2Flightning%2Fr%2FOpportunity%2F’+Opportunity.Id+’%2Fview’),
      URLFOR(‘/apex/CivilBidBookNewButton?oppId=’+Opportunity.Id)
      )}

  39. Hi,
    I used lightning URL for creating Quote with a default value and it’s working fine. But in the classic URL, When creating a Quote its automatically added Quote line item as an Opportunity line item.

    The same functionality is not working in the lightning. The quotes line item is not created in the lightning using the LIghtning URL.
    Can anyone suggest how it will work in the lightning?

    1. {!IF($User.UIThemeDisplayed=”Theme4d”,

      URLFOR(‘/lightning/o/Quote/new?navigationLocation=RELATED_LIST&backgroundContext=%2Flightning%2Fr%2FOpportunity%2F’ + Opportunity.Id + ‘%2Fview&defaultFieldValues=Name=’ + Opportunity.Name + ‘,ExpirationDate=’+ TEXT(TODAY() + 30) + ‘,OpportunityId=’ + Opportunity.Id + ‘,AccountId=’ + Opportunity.AccountId + ‘,BillingName=’ + Account.Name + ‘,ShippingName=’ + Account.Name + ‘,BillingStreet=’ + Account.Billing_Address1__c + ‘,ShippingStreet=’ + Account.Shipping_Address1__c + ‘,BillingCity=’ + Account.Billing_City__c + ‘,ShippingCity=’ + Account.Shipping_City__c + ‘,BillingState=’ + Opportunity.Account_Billing_State__c + ‘,ShippingState=’ + Opportunity.Account_Shipping_State2__c + ‘,BillingPostalCode=’ + Account.Billing_Zip__c +’,ShippingPostalCode=’ + Account.Shipping_Zip__c + ‘,BillingCountry=’ + Opportunity.Account_Billing_Country__c + ‘,ShippingCountry=’ + Opportunity.Account_Shipping_Country__c + ‘,Quote.Lightning__c=True’
      ), ”
      )}

      1. Hey Mayank, did you resolve the syncing issue?
        I’m facing the same issue and using your suggestion doesn’t work for me.
        I notice you’ve got a custom Quote.Lightning__c flag, are you doing a post insert process where if that is TRUE, then you go and stamp Opportunity.SyncedQuoteId = CurrentQuoteId
        Thanks!

  40. Hi,

    I need to create a new button on Opportunity product related list. I created the button. I want when I clickon this new button it takes me to Add Product page.
    How can I do this? Does soemone has URL parameters for Add product?

    Thanks,

  41. If anyone trying to avoid recordtypeid in the button code, you can use custom setting or a custom label like below, this worked for me.
    recordTypeId={!$Label.labelname}
    or
    recordTypeId= {!$Setup.CustomSettingName__c.CustomFieldName__c}

  42. Hi,
    Has anyone tried to make these prefilled fields non editable in the custom button through URL Hack?

  43. As far as I know the Experience Cloud(community) share the same button with Lightning page, and url hacking is not working in Experience Cloud , anybody konw how to fix it? thanks a lot!

    1. Did you find any solution for showing the button in experience cloud. We are having the same issue, the button works for lightning experience, Salesforce Mobile App but it does not work in experience cloud. Upon click it immediately goes back to the home page. Please let me know if any one is able to find a solution for experience cloud.

  44. Hi,
    For prepopulating field values i have used these in button /lightning/o/Task/new?&defaultFieldValues=WhatId={!Kidney_Donor__c.Id}
    But in classic these button is not working, please let me know how to use in classic for pre-populating the field values

  45. Hello this button works perfectly for Internal Users. What would be the hack for Partner Community? I am stuck with this. Any thoughts?

  46. Do these URL Hacks have difficulty with Custom Objects? The excellent examples you’ve provided and I’ve seen elsewhere are always on a Standard Object.

Add Comment