top of page
Search

Salesforce Hacks # 5 : Custom New Object button and option to select Record Types

  • caleksiev
  • Nov 2, 2022
  • 2 min read

Updated: Sep 20, 2023

This one kept me occupied for at least 2 hours until I figure out what was the problem, so in order to remember what I have done and hopefully help someone not to loose any time, I decided to share this scenario with you.


THE PROBLEM


So, the task is the following: we have couple of opportunity record types and I want to be able to create a new opportunity, choose the record type AND I want to be able to do this from an Account object page AND to have the Account ID preselected on the newly created opportunity.


When I click: Opportunities Tab

New button

I got the record type selection window, so far so good.

When I try to add a button on the Account page, I get this problem

If I try to add it as a New Action:

Action Type - Create a Record

Target Opportunity - Opportunity

Record Type - Uhhhh, I want all please!

I am not able to choose all of the record types and I did not want to use any Visualforce / LWC solution. So,


THE SOLUTION


On the Account object ( in my case ):

Buttons, Links, and Actions

New Button or Link

Label - New Opportunity Type

Display Type - Detail Page Button

In the formula window ( now comes the fun part ), add this line:


/lightning/o/Opportunity/new?useRecordTypeCheck=1&defaultFieldValues=AccountId={!Account.Id}


SAVE

Go to Page Layouts

Account Layout

Mobile & Lightning Actions

Drag and drop the newly created button



SAVE


The moment of truth! Go to Account, click a random Account record and check the button we just created:


CLICK IT! CLICK IT! CLICK IT! Sorry, can't help it, I am excited:


YEAAAAAAAH!!!! We can choose the opportunity record type! Click Next:


Check our predefined Account Name in the proper field! Cool, huh?

Let's check what we did in the formula:

/lightning/o/Opportunity/ - this is part of a link, when creating an Opportunity, the "normal" way

new? - we want to create new record

useRecordTypeCheck=1 - here is where the magic starts. We are saying that this "checkbox" must be true in order to see the choose record type window

defaultFieldValues=AccountId={!Account.Id} - we want the AccountId field to be populated even before we open the window with the opportunity fields and we are passing the Account Id of the record we are triggering the operation ( from which Account record did we clicked New Opportunity Type button ).

That's it, hope it helps!!! :)


NOTE: link to ideas.salesforce:

 
 
 

5 comentários


robles.yvonne
25 de set. de 2023

Hello,


Thanks so much for the above formula. I am trying to use this in a custom "New Event" scenario to select a record type associated with a custom page layout. My hurdle is getting the new event to relate to the account. For whatever reason the Related To Account field will not prefill with the account that the user is in, etc. This is what I have:


/lightning/o/Event/new?useRecordTypeCheck=1&defaultFieldValues=AccountId={!Account.Id}, WhatId={!Account.Id}


Thanks in advance for your help. :)


Curtir

jessicapokora
28 de jul. de 2023

Hi, I'm trying to default more field values but I'm not sure how to format the formula. This is what I have:

/lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=Order__c={!Order.Id}

I'm creating a case from the Order and I want to default the Order field with the Order which is working above, but if I add more default values it won't work.

Here's what I tried:

/lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=Order__c={!Order.Id}&defaultFieldValues=ContactId={!Order.Patient_Contact_ID__c}

Curtir
caleksiev
28 de jul. de 2023
Respondendo a

Hi, there! Check this out, I hope it gives a better idea of how it works. If you want, you can always contact me directly on Linkedin https://www.linkedin.com/in/tsenko-aleksiev-salesforce/ Use comma to separate other default values. You can add picklist values as well, not just fields in {!some_field} format My test link button: /lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=ContactId={!Order.BillToContactId},Type=Structural,Status=Working,Origin=Web,Priority=Medium Result:


For yours it should be something like: /lightning/o/Case/new?useRecordTypeCheck=1&defaultFieldValues=Order__c={!Order.Id},ContactId={!Order.Patient_Contact_ID__c}

Curtir

patricia.mozzoni
14 de nov. de 2022

I wish I could get this to work from the Account to create an opportunity but I cannot get the Opportunity button to show in Lightning. I add it to the page layout but it does not display.

Curtir
caleksiev
14 de nov. de 2022
Respondendo a

Hi there, Patricia! I would love to help! Could you add some screen shots to check them? Are you sure you are adding it to the "Mobile and Lightning Actions"? If you want, we can try to make a quick video call and to help you out

Curtir

Proudly created with Wix.com

bottom of page