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
mallikhajuna gundamallikhajuna gunda 

How to edit the existing records in lightning

Hi hall,

if i click on the existing records,i need to edit the  records.
please do i needful urgently
here i am poste the my code:

Apex controller::
public class SaveRecord_Lightning {
    @AuraEnabled
    public static list<Account>getAllRecords(){
        return [select id,name,AccountNumber from Account];
    }
    
    @AuraEnabled
    public static Account SaveRecord(Account RecordDetail){
        upsert RecordDetail;
        
        Return RecordDetail;
    }
}

saverecord.cmp:
<aura:component controller="SaveRecord_Lightning" >
    <aura:attribute name="RecordDetails" type="Account[]"/>
    <ltng:require styles="resource/slds235"/>
    <!--<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
    <!--setting the default value-->
    <aura:attribute name="newrecordDetails" type="Account" default="{'sobjectType':'Account','Name':'',
                                                                    'AccountNumber':''}"/>
    
    <!--inputform using component-->
    <div class="slds-align--absolute-center">
    <div class="EmpName">
        
    <div class="container">
      <form class="slds-form--stacked">
          <div class="slds-form-element slds-is-required">
              <div class="slds-form-element__control">
       <ui:inputText aura:id="EmpName" value="{!v.newrecordDetails.Name}" label="Name" class="slds-input"  labelclass="slds-form-element__label" required="true"/>
                               
              </div>
          </div>
        <div class="slds-form-element__control">
       <ui:inputText aura:id="EmMobile" value="{!v.newrecordDetails.AccountNumber}" label="Account Number" class="slds-input"  labelclass="slds-form-element__label" required="true"/>
         </div>
          <div class="slds-form-element">
              <ui:button label="submit" buttontype="submit" class="slds-button slds-neutral" labelclass="label" press="{!c.createRecord}"/>
          </div>
          <div class="slds-form-element">
              <ui:button  label="View" press="{!c.doinit}" />
          </div>
        </form>
    </div>
    </div>
    </div>
    <!--End of the Inputform-->
    <!--Data table-->
    
    <table class="slds-table slds-table--bordered slds-table--cell-buffer" style="width:800px">
  <thead>
    <tr class="slds-text-title--caps">
      <th>
               <span class="slds-truncate" title="Name">Name</span>      
            </th>
      <th>
               <span class="slds-truncate" title="AccountNumber">AccountNumber</span>      
            </th>
      
      </tr>
  </thead>
  <tbody>
      <aura:iteration items="{!v.RecordDetails}" var="c">
    <tr>
      
      <td scope="row">
                  <div class="slds-truncate" title="{!c.Name}"><a>{!c.Name}</a></div>
               </td>
      <td scope="row">
          <div class="slds-truncate" title="{!c.AccountNumber}"><a>{!c.AccountNumber}</a></div>
               </td>
      
    </tr>
    </aura:iteration>
  </tbody>
</table>
</aura:component>

controller js

({
    doinit : function(component, event, helper) {
        helper.getAllRecords(component);
    },
    createRecord:function(component, event, helper) {
        var newrecordDetails=component.get("v.newrecordDetails");
        helper.createRecord(component,newrecordDetails);
    },
    
    Edit:function(component, event, helper) {
        
    }
})

Helper js:
({
    getAllRecords : function(component) {
        
        var action = component.get("c.getAllRecords");
        action.setCallback(this,function(a){
                var state = a.getState();
            if (component.isValid() && state === "SUCCESS") {
                var result = a.getReturnValue();
               component.set("v.RecordDetails",result);
            }
            });
$A.enqueueAction(action);
             
    },
    
    createRecord : function(component,RecordDetail){
        this.upsertrecord(component,RecordDetail, function(response){
            var RecordDetails=component.get("v.RecordDetails");
            var newrecordDetails=component.get("v.newrecordDetails");
            RecordDetails.push(response.getReturnValue());
            component.set("v.RecordDetails",RecordDetails);
            var records={'sobjectType':'Account','Name':'','AccountNumber':''};
                component.set("v.newrecordDetails",records);
                  
            
        });
    },
    
    upsertrecord : function(component,Record,callback){
        var action=component.get("c.SaveRecord");
          action.setParams({ "RecordDetail" : Record});
        if(callback){
            action.setCallback (this,callback);
                
            
        }
      $A.enqueueAction(action); 
        
    }
    
})