function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt Johnson 23Matt Johnson 23 

Custom Apex Buttom from Classic Not Working in Lightning

We have some custom buttons on the Opportunity Object that work in Classic but do not working in Lightning. The buttons allow our development staff to open an Opportunity from the Contact page and some information like Opportunity Name, Account Name and Primary Contact are prefilled. This works in Classic but with the switch to Lightning those three fields do not get autopopulated when the button is used. I will also share screenshots for what the coding is for the custom and standard buttons.

Can someone tell me how to replicate this behavior in Lightning?

See the screenshots of the custom "New Contact Donation (501)" button and the standard/native "New Contact Donation (Managed). One other thing that I've noticed is that when I switch to Classic and try out the buttons the custom button fills out the Opportunity Name, Account Name and Primary Contact fields on the new Opportunity but the standard/native only fills out the Opportunity Name and Account Name... doing nothing with the Primary Contact field.

Thank you very much,

User-added imageUser-added image
Best Answer chosen by Matt Johnson 23
Matt Johnson 23Matt Johnson 23
I also opened a discussion on Power of Us hub and this is the solution that I used to solve my problem: https://powerofus.force.com/s/question/0D51E00005BtEgx/custom-apex-buttom-from-classic-not-working-in-lightning?s1oid=00D00000000hWLM&s1nid=0DB800000004Fa7&emkind=chatterCommentNotification&s1uid=0058000000Aolmb&emtm=1580298038705&fromEmail=1&s1ext=0

All Answers

Rushikesh KhandaleRushikesh Khandale
Hi Matt,
The above buttons use URL hacking to autopopulate the fields which is not supported in Lightning Experience.
Have a look at this web page that may help you or give you some information regarding your concern.
https://www.linkedin.com/pulse/salesforce-lightning-url-hacking-alternatives-keith-mcrae
Matt Johnson 23Matt Johnson 23
Okay, I started this process but now I could use a little more help. The three fields that I would like to auto-fill as the new Quick Action runs are:
 
Opportunity Name
Account Name
Primary Contact
 
I don't know the correct way to create these fields so that as someone uses this Quick Action button that creates a new Oppotunity these three fields fill out correctly.
 
The Opportunity Name would be, however the Predefined Field Values do not allow me to use this setting:
{!Account.Name} - {!RecordType.Name}
 
The Account Name would be the name of the associated Account from which this Opportunity is being created from
 
The Primary Contact would be the Primary Contact on the Contact record from which this new Opportunity is being created via this New Membership - Quick Action.
 
Thank you for helping me understand how these Quick Actions are built. I read the supporting SF documentation but it's all pretty basic without any detailed information about how to actually get New Records to populate with this information.

User-added image
Rushikesh KhandaleRushikesh Khandale
If you want all the new opportunity to be of a specific record type then you have to select that record type in the Quick Action. Also account Name is lookup field for which you have to select the {!Contact.AccountId} and Primary Contact will be {!Contact.Priamry_Contact__c}
User-added image
but if you want the record type to be dynamic then I suggest creating an Aura Component and adding it to the Quick action (New Action -> Action Type = Lightning Component). In that way you will have the flexibility to dynamically prepopulate the fields. Also by using an Aura component you will be able to overcome limitation of Create Record quick action which does not allow to use all the fields on the layout.
 Reffer the following if you opt to use the Aura component.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_create_record.htm


 
Matt Johnson 23Matt Johnson 23
Thank you Rushikesh! I will look into the Aura Component options. I think I have it working with a simple Quick Action though, so I'm not sure I'll ultimately need the Aura Component, but it's good to know what the options are!
Rushikesh KhandaleRushikesh Khandale
Hope your problem is solved.
If it is then kindly mark it as solved so that it may help others in future.

Thanks and Regards
Matt Johnson 23Matt Johnson 23
I also opened a discussion on Power of Us hub and this is the solution that I used to solve my problem: https://powerofus.force.com/s/question/0D51E00005BtEgx/custom-apex-buttom-from-classic-not-working-in-lightning?s1oid=00D00000000hWLM&s1nid=0DB800000004Fa7&emkind=chatterCommentNotification&s1uid=0058000000Aolmb&emtm=1580298038705&fromEmail=1&s1ext=0
This was selected as the best answer