Apex Controller
public class InsertAccWithConOpp{
@AuraEnabled
public static String createparentchildrecord(Account acc, Contact con, Opportunity opp){
String resultVal ='';
SavePoint sp = Database.setSavePoint();
try{
insert acc;
con.AccountID = acc.id;
insert con;
opp.AccountID = acc.id;
insert opp;
resultVal=''+acc.ID;
}
catch(Exception e){
Database.rollback(sp);
}
return resultVal;
}
}
Component : InsertAccountContactOpportunity
<aura:component controller='InsertAccWithConOpp' implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:attribute name='acc' type='Account' default="{SobjectType :'Account'}"/>
<aura:attribute name='con' type='Contact' default="{SobjectType :'Contact'}"/>
<aura:attribute name='opp' type='Opportunity' default="{SobjectType :'Opportunity'}"/>
<aura:attribute name='myVal' type='String'/>
<aura:attribute name='resultVal' type='String'/>
<div class="outerbox">
<lightning:card title='sObject Form'>
<div class="innerbox">
<lightning:tabset selectedTabId='{!v.myVal}'>
<lightning:tab label='Account' id='accId'>
<lightning:input label='AccountName' value='{!v.acc.Name}'/>
<lightning:input label='Phone' value='{!v.acc.Phone}'/>
<lightning:input label='AnnualRevenue' value='{!v.acc.AnnualRevenue}'/>
<lightning:button label='Next' onclick="{!c.nextFunction}"/>
</lightning:tab>
<lightning:tab label='contact' id='conId'>
<lightning:input label='FirstName' value='{!v.con.FirstName}'/>
<lightning:input label='LastName' value='{!v.con.LastName}'/>
<lightning:button label='Previous' onclick='{!c.prevFunction}'/>
<lightning:button label='Next' onclick='{!c.nextFunction}'/>
</lightning:tab>
<lightning:tab label='opportunity' id='oppId'>
<lightning:input label='opportunity Name' value='{!v.opp.Name}'/>
<lightning:input label='Stage' value='{!v.opp.StageName}'/>
<lightning:input label='Close Date' value='{!v.opp.CloseDate}' type='Date'/>
<lightning:button label='Previous' onclick='{!c.prevFunction}'/>
<lightning:button label='submit' onclick='{!c.submitFunction}'/>
</lightning:tab>
</lightning:tabset>
</div>
</lightning:card>
</div>
</aura:component>
JS Controller
({
nextFunction : function(component, event, helper) {
var val = component.get('v.myVal');
if(val == 'accId'){
component.set('v.myVal','conId');
}
else if(val == 'conId'){
component.set('v.myVal','oppId');
}
},
prevFunction : function(component, event, helper) {
var val = component.get('v.myVal');
if(val=='conId'){
component.set('v.myVal','accId');
}
else if(val=='oppId'){
component.set('v.myVal','conId');
}
},
submitFunction : function(component, event, helper) {
var accs =component.get('v.acc');
var cons =component.get('v.con');
var opps =component.get('v.opp');
var action = component.get('c.createparentchildrecord');
action.setParams({'acc':accs, 'con':cons, 'opp':opps});
action.setCallback(this, function(response){
var state = response.getState();
if(state === 'success'){
var r = response.getReturnValue();
component.set('v.resultVal',r);
}else{
//console.log('failed');
component.set('v.resultVal','failed');
}
});
$A.enqueueAction(action);
}
})
Style
.THIS.innerbox{
width:350px;
height:400px;
padding:20px;
margin-left:20px;
border:2px solid blue;
}
.THIS.outerbox{
width:450px;
height:370px;
padding:20px;
border:2px solid blue;
margin-left:450px;
margin-top:20px;
}
Application
<aura:application extends="force:slds">
<c:InsertAccountContactOpportunity/>
</aura:application>
Output