+ Start a Discussion
SFDC GuestSFDC Guest 

Display lightning form in modal after clicking on standard new button of contact

I am trying to display below lightning form in modal popup using overlay library. Please let me know how to do. 
I have overrided below form with Contact New button. Thanks.
    
    <aura:component implements="force:appHostable,lightning:actionOverride" access="global" >
    <aura:attribute name="recordId" type="String" /> <lightning:overlayLibrary aura:id="popuplib"/>
    <div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
        <lightning:recordEditForm objectApiName="Contact" onsuccess="{!c.handleSuccess}">
            <lightning:messages />
            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" />
            <lightning:inputField fieldName="Birthdate" />
            <lightning:inputField fieldName="Phone" />
            <lightning:button aura:id="submit" type="submit" label="Save record" class="slds-m-top_medium" />
            </lightning:recordEditForm>
    </div>  
</aura:component>

Client side controller:

({
    handleSuccess : function(component, event, helper) {
        
        var contactRec = event.getParams().response;
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
           "recordId": contactRec.id,
           "slideDevName": "related"
       });
        
       navEvt.fire();
    }  
})
Xovo LarjemXovo Larjem
Was looking for the same and this thread is what I came through: https://salesforce.stackexchange.com/questions/230124/display-lightning-form-in-modal-after-clicking-on-standard-new-button-of-contact  (https://salesforce.stackexchange.com/questions/230124/display-lightning-form-in-modal-after-clicking-on-standard-new-button-of-contact )
See if this fetches any help to you.

With Regards,
Protar https://plex.software/ https://tutuappx.com/ https://vidmate.onl/
Alain CabonAlain Cabon
Hi,

<lightning:recordEditForm> is not perfect: https://success.salesforce.com/issues_view?id=a1p3A000000FmjRQAS

You need a calling component included into a Lex record page (important). You cannot test this code with a basic application.
A new component like below for a test and you need to put it on a record page ( (wheel) > Edit Page )
<aura:component implements="flexipage:availableForAllPageTypes,lightning:actionOverride,force:hasRecordId,force:hasSObjectName">
    <lightning:overlayLibrary aura:id="overlayLib"/>
    <lightning:button name="modal" label="Show Modal" onclick="{!c.handleShowModal}"/>
</aura:component>
Its controller below creating the modal: $A.createComponent("c:ModalTest", {recordId:recId},
({
    handleShowModal: function(component, evt, helper) {
        var modalBody;
        var recId= component.get('v.recordId');
        $A.createComponent("c:ModalTest", {recordId:recId},
           function(content, status) {
               if (status === "SUCCESS") {
                   modalBody = content;
                   component.find('overlayLib').showCustomModal({
                       header: "Contact Quick Edit",
                       body: modalBody, 
                       showCloseButton: true,
                       closeCallback: function() {
                           alert('You closed the modal!');
                       }
                   })
               }                               
           });
    }
})
ModalTest:
<aura:component >
    <aura:attribute name="recordId" type="String" />
    <aura:attribute access="private" name="error" type="String" default=""/>
    <div class="slds-p-bottom_large slds-p-left_large" style="width:500px">      
        <aura:if isTrue="{! !empty(v.error)}">
            <ui:message title="Error" severity="error" closable="true">{!v.error}</ui:message>
        </aura:if>
        <lightning:recordEditForm recordId="{!v.recordId}"  objectApiName="Contact"  onsubmit="{!c.handleSubmit}" onerror="{!c.handleError}" onsuccess="{!c.handleSuccess}">
            <lightning:messages />
            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" />
            <lightning:inputField fieldName="Birthdate" />
            <lightning:inputField fieldName="Phone" />
            <lightning:button aura:id="submit" type="submit" label="Save record" class="slds-m-top_medium" />
            <lightning:button aura:id="cancel" onclick="{!c.handleCancel}" label="Cancel" class="slds-m-top_medium" />
        </lightning:recordEditForm>
    </div>  
</aura:component>
Controller of ModalTest :
({
    handleError : function(component, event, helper) {
        console.log('error');
    },
    handleCancel : function(component, event, helper) {
        //closes the modal or popover from the component  
        helper.closeModal(component,event);
    },
    handleSubmit : function(component, event, helper) {
        console.log('submit');      
        var contactRec = event.getParams().fields;     
        var fields = JSON.stringify(contactRec);
        console.log(fields);  
        var errorfields = '';
        var sep = '';
        for (var f in contactRec) {
            console.log('field:' + f + '=' + contactRec[f]);
            if (!contactRec[f]) {
                if (f !== 'Phone') {
                    console.log(f + ' empty and mandatory (stop)');
                    errorfields = errorfields + sep + f;
                    sep = ', ';
                    event.preventDefault();
                }             
            }
        }  
        if (errorfields !=='') component.set('v.error',errorfields+ ' must be completed');
    },
    handleSuccess : function(component, event, helper) {
        console.log('success');      
        helper.closeModal(component,event);
    }  
})

Helper of ModalTest:
({
    closeModal : function(cmp,event) {
        var contactRec = event.getParams().response;
        console.log(JSON.stringify(contactRec));
        
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": cmp.get('v.recordId'),
            "slideDevName": "related"
        });
        
        navEvt.fire();
    }
})

handleSubmit : function(component, event, helper) is complicated because of a the bug 
https://success.salesforce.com/issues_view?id=a1p3A000000FmjRQAS

There are many alternatives with the modals (more or less components and/or dynamically created)
Betty BakerBetty Baker
That's good to know! Thank you! 
happy wheels (https://happywheels2.io)
Aqib AnjumAqib Anjum
That acutally worked, Thank you!
offshore hosting (https://offshorededi.com/).
Aqib AnjumAqib Anjum

It worked.

Here I have collected a list of Best Instagram Captions (https://quotesology.com/instagram-captions/). Sassy Captions, Cool Captions, Love Captions, Funny Captions & Cute Captions for Instagram.

offshore hostingoffshore hosting
Really great !
Offshore web hosting  (https://offshorededicated.net/)
Sean EdwardsSean Edwards

This information has been very difficult for me, thank you.

basketball legends fun (https://basketballlegends.fun)

Sonia AroraSonia Arora
This is really a nice blog. Very useful and informative. Keep posting! satta matka (https://sattamatka.market/)
Narayan AddyNarayan Addy
Thank you so much for sharing this Informative article with us. I really love the way of your presentation. Please keep sharing more Satta Matka (https://sattamatkash.com)
 
Christine ArmstrongChristine Armstrong
Thanks for share this great info usefull articles keep it up.If you're looking for the best free fonts on the internet then look no further! We've rounded up 73 stunning fonts to make your designs stand out.https://fontschoice.com/
Justin M. JacksonJustin M. Jackson

Thanks, Very useful and informative. Keep posting

Rumblerum (https://www.rumblerum.com/)

Justin M. JacksonJustin M. Jackson

Also. (https://best-microphones.com/

({
    closeModal : function(cmp,event) {
        var contactRec = event.getParams().response;
        console.log(JSON.stringify(contactRec));
        
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": cmp.get('v.recordId'),
            "slideDevName": "related"
        });
        
        navEvt.fire();
    }
})
Can we use multiple variables? , or we have to copy it exatly. (https://getmylaptop.com/)
Digital Web ServicesDigital Web Services
Many time i am learning from online platform becasuse of lots of discount and saving from Udmey coupon  (https://www.digital-web-services.com/udemy-coupon-code.html) but this form section is also good to get free information and knowledge. Keep it up.
B GamesB Games
nice work I have read this is a very helpful slope (http://www.y8games.net/games/slope) thanks