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
Javier CGJavier CG 

URL hack don´t pass parameters to create new record in lightning experience

I have to remove javascript buttons to adapt it to lightning experience (LE).
I have created a custom button to create a new record, and like the new record has to receive some values from the related one, I do it with url hack, as the js button did it.
The button run perfect in classic, sending the values to the new record, but in LE the create record page opens, but not shows none of the sended values from the related record.
There exists some form to do it?
I know I would should use a quick action to create the new record in LE, but in some cases I need to change the values passed in function of the values of the related record, and I don´t know if this is possible with quick actions (ex: the record type of the new record depends of the profile of the user who creates it).
Best Answer chosen by Javier CG
Ravi Dutt SharmaRavi Dutt Sharma
Hi Javier,

You can use the defaultFieldValues attribute of force:createRecord to populate the default values in record create form.
var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Hi Javier,

You can use the defaultFieldValues attribute of force:createRecord to populate the default values in record create form.
var createAcountContactEvent = $A.get("e.force:createRecord");
createAcountContactEvent.setParams({
    "entityApiName": "Contact",
    "defaultFieldValues": {
        'Phone' : '415-240-6590',
        'AccountId' : '001xxxxxxxxxxxxxxx'
    }
});
createAcountContactEvent.fire();

 
This was selected as the best answer
Javier CGJavier CG
Thank you for your response Ravi,

But I don´t know where I must put apex code in a custom button.
Now I have a custom button with an URL content origin and I can´t find one origin content that let me put apex code inside.
Ravi Dutt SharmaRavi Dutt Sharma
You need to replace your button with a quick action. The quick action will be associated to a lightning component. You need to place this code in the JS controller of your lightning component.
Javier CGJavier CG
Thanks Ravi, but I didn´t explained well on my question.

I need to prepopulate the fields for the user, but I want that the user can change it if he wants.
With your solution I have seen that the fire method launch the layout to create a new event (I´m trying to create a new event record) with the default values that I choose, but I still having two problems:

- I need to put dynamic values depending on the values of the original record (the action executes from a lead object), and I can´t find the way to catch the original record values to work with them  (ex: the record type of the new record depends of the profile of the user who creates it).
- The lightning component window shows over the create event layout too even if I don´t put nothing inside on it. There is any form to open only the create new event window?

Sorry if my questions are silly, but it is my first contact with lightning components, I have been all the morning searching by the web and I can´t get it yet.
kev levronekev levrone
Hi there. Thanks for the information. 
Javier CGJavier CG
Ravi, I read about Lightning Component and finally I learn how to do it like you told me.
Thank you for your help