Wednesday, 9 September 2020

Create a New Opportunity From a Quick Action - Salesforce

Requirement Statement: 

"Opportunity should be created from Account page layout by using 'New Opportunity' button and while creating it should ask for record type selection option and also it should pre-populate Account Name."


Solution Approach: 

Create a custom button on Account to create Opportunity as below.

 While creating button, it will ask for Record Type to select, but the issue is that you can select only one record type. 

So, you need to create 4 custom buttons for one for each record type as I have in my org. Later you need to add these multiple custom buttons on page layout as well.

This is not the right solution approach/UI Experiece/best practice to follow. 


Solution: 

Here is solution that exact match to out requirement. Create 'Custom Button or Link' on Account as below. 

Refer the URL -

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

Parameters to remember:

1. useRecordTypeCheck=1

This will enable for the record type selection option. 

2. defaultFieldValues=AccountId={!Account.Id}

This will prepopulate Account Name on Opportunity from Account. If you want to add more fields just add '&' and add fields.
Example: defaultFieldValues=AccountId={!Account.Id}&StageName='Plan'

Then finally save and add it to page layout.

Now go to any Account record and Click on 'New Opportunity'.
 

Select the record type and click 'Next'
You can see pre-populated Account Name.

Note: Just change object name/fields as per your requirement.

This is only available for LEX, not available for Mobile.

If you like it, subscribe for more blogs and comment for feedback to motivate.
Happy Learning!!!