0

I have a requirement where on clicking on Lightning Quick Action on detail page of custom object will open a pop up asking "wheter to clone?", if user clicks Yes button in the pop up, clone event should fire showing the values of the record be displayed in edit modal pop up along with Save and cancel button (when save button is clicked a new record is created).

If user clicks No button on the pop up of  "wheter to clone?" then user will go through New record create flow (like record type selection then Create New record modal pop up).

Can you please guide me how to achieve this functionality?

Thanks in advance.

0

In order to achieve this functionality, you will need to do use an aura component which implements the force:hasRecordId and force:lightningQuickAction interfaces.

You will need to build the "Would you like to clone?" Yes/No part of the user interface within the aura component. When the user makes their selection, you must use the force:createRecord component (See Documentation here). If the user selects yes, then you will need to prompt them for record type selection, then set the default values from the current record. It might be wise to use a field set to determine which fields you want to clone.

Here is an example using the force:createRecord where you set default values:

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

In order to fetch the record types, you must do something like this:

<lightning:radioGroup
 name="radioGroup"
 options="{! v.recordTypeOptions }"
 value="{! v.selectedRecordTypeId }"
 type="radio"/>

private static List<RadioOption> getRecordTypeValues(String objectName) {
    list<RadioOption> returnValue = new List<RadioOption>();
    List<Schema.RecordTypeInfo> recordtypes = Schema.getGlobalDescribe().get(objectName).getDescribe().getRecordTypeInfos();
    for(RecordTypeInfo rt : recordtypes) {
        if(rt.getName() != MASTER && rt.getName().trim() != '' && rt.isAvailable()) {
            RadioOption option = new RadioOption();
            option.value =  rt.getRecordTypeId();
            option.label =  rt.getName();
            returnValue.add(option);
        }
    }
    return returnValue;
}

public class RadioOption {
    @AuraEnabled
    public String value {get; set;}
    @AuraEnabled
    public String label {get; set;}
}
| improve this answer | |
  • Thanks for the reply and my sincere apologies for not replying quickly. I have implemented as per you instructions and able to achieve Clone, but while trying for New record createAccountContactEvent.fire() is not giving the option to select Record Type, by default it is selecting the record type on details page record type on which we were clicking the "whether to clone". So directly getting landed on New object creation screen rather than record selection screen, is there any way we can get the record selection screen. Thanks in advance – getty Apr 20 at 17:55
  • You must build the record type selection, then fire the createRecord event. I have added the apex up above to describe how to fetch the recordtypes. – Mitch Spano Apr 20 at 18:14
  • I cannot add radiogroup in the Modal pop up of 'whether to clone", as it might confuse user while they want to go with clone option – getty Apr 21 at 12:06
  • Got it, I need to hide radiogroup in the component. sfdcmonkey.com/2017/05/09/… Need to set radiogroup instead of list. – getty Apr 21 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.