+ Start a Discussion
SFDC@ErrorSFDC@Error 

Update specific field using data services

Hi All,

How can i update specific field uisng data services like  on click on button it will open pop up and display specicif field to upadte.
Alain CabonAlain Cabon
The easiest way is to use:  <lightning:inputField fieldName="{!myfield}"/> inside a <lightning:recordEditForm> with an <aura:iteration>

The fields 'Name', 'Industry' and 'Website' of Account are displayed dynamically without a complex component creation (a list is sufficient). 
 
<aura:component implements="force:lightningQuickAction,force:appHostable,flexipage:availableForRecordHome,force:hasRecordId"> 
    <aura:attribute name="showSpinner" type="Boolean" default="false" />   
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="myfields" type="List" default="[]"/>
    
    <aura:if isTrue="{!v.showSpinner}">
        <lightning:spinner />
    </aura:if>
    
    <lightning:notificationsLibrary aura:id="notifLib1" />       
    
    <lightning:card>    
        <lightning:recordEditForm 
                                  recordId="{!v.recordId}"
                                  objectApiName="Account"
                                  onload="{!c.handleLoad}"
                                  onsuccess="{!c.handleSuccess}"
                                  onerror="{!c.handleError}">
            <lightning:messages />
            <aura:iteration items="{!v.myfields}" var="myfield">
                <lightning:inputField fieldName="{!myfield}"/><br/> 
            </aura:iteration>         
            <lightning:button class="slds-m-top_small" type="submit" variant="brand" label="Save" onclick="{!c.handleSave}" />
        </lightning:recordEditForm>
    </lightning:card>
    
</aura:component>
 
({
     doInit: function(cmp) {
         cmp.set('v.myfields', [ 'Name', 'Industry', 'Website' ]);
    },
    handleSuccess: function (cmp, event, helper) {
        cmp.find('notifLib1').showToast({
            "title": "Record updated!",
            "message": "The record has been updated successfully.",
            "variant": "success"
        });
        cmp.set("v.showSpinner", false);
    },
    handleError: function (cmp, event, helper) {
        cmp.find('notifLib1').showToast({
            "title": "Something has gone wrong!",
            "message": event.getParam("message"),
            "variant": "error"
        });
    },    
    handleLoad : function(cmp, event, helper) {
        cmp.set("v.showSpinner", false);
    },   
    handleSave : function(cmp, event, helper) {
        cmp.set("v.showSpinner", true);
    },
})