0

enter image description hereWe are migrating our code to lightning. We have a javascript button in case object which opens up a custom object create new record page with pre-populated values from case. How can i do the same thing in lightning?.

We tried multiple ways but the values are not getting populated. The custom object got 2 lookup fields for case and contact. Which i need to pre-populate.

srcUp('/{!$Setup.customSetting.Prefix__c}/e?{!$Setup.customSetting.Case_Field__c}={!Case.CaseNumber}&{!$Setup.customSetting.Case_Field__c}_lkid={!Case.Id}&{!$Setup.customSetting.Contact_Field__c}={!Contact.Name}&{!$Setup.customSetting.Contact_Field__c}_lkid={!Contact.Id}') 

field IDs we have saved in the custom setting in the above.

1 Answer 1

2

You would typically create a Quick Action that calls a controller method, which in turn fires off a force:createRecord event. The example in the documentation provides the necessary code:

var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();

All you need to do is create a new component that serves as a Quick Action to initialize your component, then fire off this event. The platform will take care of the rest for you.

Note that you can now use the standard API names, instead of maintaining custom settings that keep track of the field ID. You may need to combine this with force:recordData in order to bring in current record information.

There's other (recent) examples of this if you just search for the term here on the Salesforce StackExchange.

3
  • Thanks for the idea. But in the org case Feed is enabled and hence the quick action buttons come below the feed. Client wants the buttons only in the header. Is there any way to move the quick action buttons to header?
    – bksfdc
    Commented Dec 21, 2017 at 5:58
  • @bksfdc Not sure why I didn't see your message before, but I'd recommend firing off a force:closeQuickAction to get rid of the action itself, since it's not needed.
    – sfdcfox
    Commented Dec 24, 2017 at 7:34
  • i dont think i have got point. Can you please give bit more detail
    – bksfdc
    Commented Dec 27, 2017 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .