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
Nevin O'Regan 3Nevin O'Regan 3 

create multiple contacts from within one component

Hi guys,

I'd like to be able to create multiple contacts from within one component and relate them to the same account. 
The component will added to a Contact where type = Main Applicant. When a user clicks on a "Create" button they should be able to create as many contacts from here as they need to capture Spouse, Children etc. 
Has anyone developed something similar? 
Raj VakatiRaj Vakati
try like this use quick action 
 
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" controller="ContactCreare">
    
    <div class="slds-align--absolute-center">
        <lightning:button aura:id="saveBtn" variant="neutral" label="Save"  onclick="{!c.saveContact}"/>
        <lightning:button aura:id="saveBtn" variant="neutral" label="Cancel"  onclick="{!c.cancel}"/>
        
    </div>
    
</aura:component>
 
({
    saveContact : function(component, event) {
        var action = component.get("c.changeOwner");
        action.setParams({"recordId" : component.get("v.recordId")});
        action.setCallback(this, function(response) {
            var state = response.getState();
            
            var resultsToast = $A.get("e.force:showToast");
            if (state == "SUCCESS") {
                resultsToast.setParams({
                    "type":"success",
                    "title": "Save Success!",
                    "message": "Contact create!"
                });
                resultsToast.fire();
            }else{
                
              
            }
            
            var dismissActionPanel = $A.get("e.force:closeQuickAction");
            dismissActionPanel.fire();
            $A.get('e.force:refreshView').fire();
            
            
        });
        $A.enqueueAction(action);
    },
    cancel:function(component){
        var dismissActionPanel = $A.get("e.force:closeQuickAction");
        dismissActionPanel.fire();
    }
})
 
public class ContactCreare {
    @AuraEnabled
    public static void changeOwner(String recordId){
        
		Contact c1 = new COntact() ;
		c1.LastName='Test';
		c1.AccountId =recordId ;
		insert c1 ;
		
		Contact c2 = new COntact() ;
		c2.LastName='Test';
		c2.AccountId =recordId ;
		insert c2 ;
		
		
		Contact c3 = new COntact() ;
		c3.LastName='Test';
		c3.AccountId =recordId ;
		insert c3 ;
		
		
    }
}

 
Nevin O'Regan 3Nevin O'Regan 3
Thanks Raj,

I will try this out.