The scenario is I want to display Opp contact, edit and add new fields of that contact in single component.

Ex: I am displaying a Contact Name, Role. I want to edit the existing one as well as when clicking "Add" should add new Contact Name and Role fields to that table.

<aura:component controller="OCR" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
    <aura:attribute name="options" type="List" default="[
                                                    {'label': 'Primary Contact', 'value': 'Primary Contact'},
                                                    {'label': 'Business Contact', 'value': 'Business Contact'},
                                                    {'label': 'Primary Attendee', 'value': 'Primaey Attendee'},

 <lightning:card title="Contacts">
     <aura:iteration items="{!v.OList}" var="O">
     <lightning:layout multipleRows="true">
        <lightning:layoutItem size="6" padding="around-small">
             <input id="form-element-01" class="slds-input"  value="{!O.Contact.Name}" />

         <lightning:layoutItem size="6" padding="around-small">

             <input class="slds-input" value="{!O.Role}"/>


     <div class="slds-m-around--xx-small">
     <div class="slds-float_right slds-p-bottom_small">
                <lightning:buttonIcon iconName="utility:add"  size="large" variant="bare" alternativeText="Add" onclick="{!c.addRow}"/>

                <button class="slds-button slds-button_neutral slds-button_stretch">Save and Continue</button>

     // Fetch the accounts from the Apex controller
      fetchAcc : function(component, event, helper) {
        var action = component.get("c.fetchOCR");
        action.setCallback(this,function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.OList", response.getReturnValue());
    handleClick: function(component){
        alert: "Add Contact"

    add : function(component, event, helper) {
        var addRec = {'sobjectType' : 'OpportunityContactRole','ContactId' : '','Role' : '' };
        var existingRecords = component.get("v.OList");
        component.set("v.OList", existingRecords);
  • 2
    Hi Sonia, welcome to SFSE! Please take the time to visit the Help center and read How do I ask a good question. If you post what you've written so far and where you're stuck, I'm confident you'll find plenty of people willing to assist you. SFSE is a Q&A forum where we look to help each other by asking and answering questions about real problems or errors with our code. Posting requests to write code for you generally get closed. – crmprogdev Oct 7 '19 at 15:46
  • I am asking for an idea no need of code. @crmprogdev Anyway I will post what I've tried so far. – Sonia Oct 7 '19 at 17:15
  • you can try lightning:recordEditForm with in aura iteration, example solution salesforce.stackexchange.com/questions/246709/… – sdandamud1 Oct 7 '19 at 21:22
  • How can we add new fields (I have a button to add new contact and role to the existing one) to the form? @sdandamud1 – Sonia Oct 8 '19 at 4:23

Your Answer

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

Browse other questions tagged or ask your own question.