• Zuzana Ros
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,

I had requirement to create 'New Contact' from lightning component on clicking the button on other lightning component, for this created the new  'CreateContact' lightning component as code shown below and screen and included that on other lightning component.

Can someone help me with code to select the record type while creating the new contact using lightning component? As of now i have defaulted the record type.

Component:

<aura:component >
    <aura:attribute name="myContactFields" type="List" default="['AccountId','LastName', 'FirstName']" />
    <aura:registerEvent name="CmpEvent" type="c:SHM_CreateContactModelClose" />
    <aura:attribute name="recordTypes" type="list" default="Business,Individual"/>
    <lightning:messages />
    <lightning:recordForm
                          aura:id ="createContactForm"
                          objectApiName="Contact"
                          layoutType="Full"
                          columns="2"
                          mode="edit"
                          recordTypeId="0120k000000HOHkAAO"
                          onsubmit="{!c.handleSubmit}"                  
                          onsuccess="{!c.handleSuccess}"
                          oncancel="{!c.handleCancel}" />
</aura:component>

JS Controller:

({
    handleSuccess : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Success!",
            "type":"success",
            "message": 'Contact Record has been created Successfully!!..'
        });
        toastEvent.fire();
        $A.get('e.force:refreshView').fire();
    },
    handleSubmit : function(component, event, helper) {
        //event.preventDefault(); // Prevent default submit
        
        component.find('createContactForm').submit(); // Submit form
        console.log('Successfully Created Contact Record');
    },
   
    handleCancel : function(component, event, helper) {
        var cmpEvent = component.getEvent("CmpEvent");
        cmpEvent.setParams({
            "closeModel" : false
        });
        cmpEvent.fire();
    },
})

Create Contact Pop Up

Thanks in Advance.
  • June 14, 2019
  • Like
  • 0