• Somu Somu
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi

Here my requirement is display all account records and mass update the records here condition is if the record check box is checked (true)then only records need to be update with out selecting check box record does not update  
(the code is updating the records with out selecting the check box but i need after selecting the checkbox then only update the records​)

User-added image
here my code is

apex:
public with sharing class massupdate
{
  
    @AuraEnabled
    public static list < Account > fetchAccount()
    {
        // query 10 records from account with their relevant contacts and return query.
        List < Account > lstOfAcc = [select Name, AnnualRevenue, BillingState, Website,Rating,Phone from Account limit 10 ];
        return lstOfAcc;
    }
     // method for update records after inline editing  
    @AuraEnabled
    public static List < account > saveAccount(List<Account> lstAccount) {
        update lstAccount;
        return lstAccount;
    }

 
}
-------------------------------------
component

<aura:component controller="massupdate">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="ListOfAccount" type="Account[]" description="store accounts with there child contacts"/>
    <div>
         <table class="table table-bordered table-hover" width="70%">
            <thead>
                <tr>
                    <th width="5%"> <strong>  Select </strong> </th>
                    <th width="20%"> <strong>  Id </strong> </th>
                    <th width="20%"> <strong>  Name </strong> </th>
                    <th width="20%"><strong> Website </strong></th>
                    <th width="20%"><strong> Phone </strong></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.ListOfAccount}" var="ac">
                    <tr>
                        <td><ui:inputCheckbox text="{!ac.Id}" aura:id="boxPack" value="" /></td>
                        <td> <a href="{! '/'+ac.Id}"> {!ac.Id} </a> </td>
                        <td><ui:inputText value="{!ac.Name}"/>   </td>
                        <td><ui:inputText value="{!ac.Website}"/>    </td>
                        <td><ui:inputText value="{!ac.Phone}"/>  </td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
            </div>
    <br/>
     <lightning:button label="Save" onclick="{!c.Save}" variant="success"/>
     <lightning:button label="Cancel" onclick="{!c.Cancel}" variant="success"/>
</aura:component>

-----------------------------------------------
controller
({
    doInit: function(component, event, helper) {
        //call apex class method
        var action = component.get('c.fetchAccount');
        action.setCallback(this, function(response)
                           {
            //store state of response
            var state = response.getState();
            if (state === "SUCCESS") {
                //set response value in ListOfAccount attribute on component.
                component.set('v.ListOfAccount', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    Save: function(component, event, helper) 
    {                            
        var newAcc = component.get("v.ListOfAccount");
        var action = component.get("c.saveAccount");
        action.setParams({"lstAccount": newAcc });
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") 
            {
                var name = a.getReturnValue();
                component.set("v.ListOfAccount", name);
                alert('Updated...');
                location.reload();
            }
        })
        $A.enqueueAction(action);
    },
    Cancel: function(component, event, helper) 
    {    
        alert('Clicked on cancled ...');
         location.reload();
    }
})


 
Hi everyone ,
here my requriment is display all contacts records in those contacts select some records. in that selected records if update any one of the record (phone field) then all selected records nees to be update(phone field) through lightning Component
 
Hi

Here my requirement is display all account records and mass update the records here condition is if the record check box is checked (true)then only records need to be update with out selecting check box record does not update  
(the code is updating the records with out selecting the check box but i need after selecting the checkbox then only update the records​)

User-added image
here my code is

apex:
public with sharing class massupdate
{
  
    @AuraEnabled
    public static list < Account > fetchAccount()
    {
        // query 10 records from account with their relevant contacts and return query.
        List < Account > lstOfAcc = [select Name, AnnualRevenue, BillingState, Website,Rating,Phone from Account limit 10 ];
        return lstOfAcc;
    }
     // method for update records after inline editing  
    @AuraEnabled
    public static List < account > saveAccount(List<Account> lstAccount) {
        update lstAccount;
        return lstAccount;
    }

 
}
-------------------------------------
component

<aura:component controller="massupdate">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="ListOfAccount" type="Account[]" description="store accounts with there child contacts"/>
    <div>
         <table class="table table-bordered table-hover" width="70%">
            <thead>
                <tr>
                    <th width="5%"> <strong>  Select </strong> </th>
                    <th width="20%"> <strong>  Id </strong> </th>
                    <th width="20%"> <strong>  Name </strong> </th>
                    <th width="20%"><strong> Website </strong></th>
                    <th width="20%"><strong> Phone </strong></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.ListOfAccount}" var="ac">
                    <tr>
                        <td><ui:inputCheckbox text="{!ac.Id}" aura:id="boxPack" value="" /></td>
                        <td> <a href="{! '/'+ac.Id}"> {!ac.Id} </a> </td>
                        <td><ui:inputText value="{!ac.Name}"/>   </td>
                        <td><ui:inputText value="{!ac.Website}"/>    </td>
                        <td><ui:inputText value="{!ac.Phone}"/>  </td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
            </div>
    <br/>
     <lightning:button label="Save" onclick="{!c.Save}" variant="success"/>
     <lightning:button label="Cancel" onclick="{!c.Cancel}" variant="success"/>
</aura:component>

-----------------------------------------------
controller
({
    doInit: function(component, event, helper) {
        //call apex class method
        var action = component.get('c.fetchAccount');
        action.setCallback(this, function(response)
                           {
            //store state of response
            var state = response.getState();
            if (state === "SUCCESS") {
                //set response value in ListOfAccount attribute on component.
                component.set('v.ListOfAccount', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    Save: function(component, event, helper) 
    {                            
        var newAcc = component.get("v.ListOfAccount");
        var action = component.get("c.saveAccount");
        action.setParams({"lstAccount": newAcc });
        action.setCallback(this, function(a) {
            var state = a.getState();
            if (state === "SUCCESS") 
            {
                var name = a.getReturnValue();
                component.set("v.ListOfAccount", name);
                alert('Updated...');
                location.reload();
            }
        })
        $A.enqueueAction(action);
    },
    Cancel: function(component, event, helper) 
    {    
        alert('Clicked on cancled ...');
         location.reload();
    }
})