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
VJ_SFDCVJ_SFDC 

Lightining reredner issue

Rerender issue in lighting component after deleting iterator is not changing.

Display checkbox for the iterator and deleting the record successfully from controller after that querying data back again and trying to refresh iterator, How do i refresh iterator list after deleting data from apex controller.
deleteSelectedHelper: function(component, event, deleteRecordsIds) {
        alert('deleteRecordsIds==='+deleteRecordsIds);
        var action = component.get('c.deleteRecords');
        action.setParams({
            "lstRecordId": deleteRecordsIds,"AccountId" : component.get("v.AccountId")
        });
        action.setCallback(this, function(response) {
           //store state of response
           var state = response.getState();
           if (state === "SUCCESS") {
                console.log(state);
               //alert(response.getReturnValue());
               //component.set('v.relatedContactsRoles', response.getReturnValue());
                if (response.getReturnValue() != '') {
                    //alert('inside of response ');
                    alert(response.getReturnValue());
                     component.set('v.relatedContactsRoles', '');
                    component.set('v.relatedContactsRoles', response.getReturnValue());
                   // alert(state);
                    
                   // alert('The following error has occurred. while Delete record-->' + response.getReturnValue());
                }else {
                    console.log('check it--> delete successful');
                }
                //this.testonLoad(component, event);
           }
          });
          $A.enqueueAction(action);
     },

This is the line using to reset records after deleting.

component.set('v.relatedContactsRoles', response.getReturnValue());


 
sfdcMonkey.comsfdcMonkey.com
hi VJ_SFDC,
what value you have in response.getReturnValue() and try to set the list with empty array
var emptyArr = [];
component.set('v.relatedContactsRoles', emptyArr );

thanks
VJ_SFDCVJ_SFDC

Hi Piyush,
Thank you for your response and changed the code as per your comment and still no luck also posting controller method. Do you see any issues?
@AuraEnabled
 	public static List<Contact_Roles__c> deleteRecords(list<String> lstRecordId,Id AccountId) {
      system.debug('========'+lstRecordId);
      List <String > oErrorMsg = new List <String> ();
      List <Contact_Roles__c> lstDeleteRec = [select Id from Contact_Roles__c where id IN: lstRecordId];
  	  Database.DeleteResult[] DR_Dels = Database.delete(lstDeleteRec, false);
      //Database.DeleteResult[] DR_Dels = Database.delete(lstDeleteRec, false);
  // Iterate through each returned result
  	 for (Database.DeleteResult dr: DR_Dels) {
           if (dr.isSuccess()) {
              system.debug('successful delete contact=========');
             // Operation was successful
           }else{
            oErrorMsg.add('');
                for (Database.Error err: dr.getErrors()) {
                 // add Error message to oErrorMsg list and return the list
                 oErrorMsg.add(err.getStatusCode() + ': ' + err.getMessage());
                }
           }
      }
        system.debug('oErrorMsg==='+oErrorMsg);
  		return  [Select Id,Type__c,Role__c,Product_Family__c,Contact__c,Primary__c from Contact_Roles__c where Account__c =:AccountId];
   }
I hope you understand my earlier explanation that the record is deleted successfully from controller method and again I am querying data, is there any chance can i delete the record from the list without passing data to the controller so that everything will happen server-side and I believe it should work.

 
deleteSelectedHelper: function(component, event, deleteRecordsIds) {
        alert('deleteRecordsIds==='+deleteRecordsIds);
        var action = component.get('c.deleteRecords');
        action.setParams({
            "lstRecordId": deleteRecordsIds,"AccountId" : component.get("v.AccountId")
        });
        action.setCallback(this, function(response) {
           //store state of response
           var state = response.getState();
           if (state === "SUCCESS") {
               alert('after delete='+state);
               alert(response.getReturnValue());
                console.log(state);
              // component.set('v.relatedContactsRoles', '');
                   // component.set("v.refreshFlag",false);
                    //alert(response.getReturnValue().length);
                   var emptyArr = [];
                      component.set('v.relatedContactsRoles', emptyArr );
                    //component.set('v.relatedContactsRoles', response.getReturnValue());
                   // component.set("v.refreshFlag",true);
               //alert(response.getReturnValue());
               //component.set('v.relatedContactsRoles', response.getReturnValue());
                if (response.getReturnValue() != '') {
                    //alert('inside of response ');
                    //alert(response.getReturnValue());
                     
                   // alert(state);
                    
                   // alert('The following error has occurred. while Delete record-->' + response.getReturnValue());
                }else {
                    console.log('check it--> delete successful');
                }
                //this.testonLoad(component, event);
           }
          });
          $A.enqueueAction(action);
     },

Actually, after deleting, I have verified that the deleted records are not there in the response.getReturnValue() meaning before delete suppose there are 10 records and i selected 2 records after that when i check with alert I could see that list is retunring 8 records only. the problem is iterator part is not refreshing. 

suppose for the div if I use aura: id="something" how do I refresh from JS so that it will work may be.
 
<div class="slds-p-around_medium" aura:id="contactRolesblock">
    <div class="slds-text-heading_large">
        Related Contacts Roles
 	</div>
      <div class="slds-align_absolute-center slds-p-bottom_small">
        <!-- <lightning:button variant="brand" label="Add New" onclick="{!c.addContactRole}" /> -->
   		<lightning:button variant="brand" label="Delete Selected" onclick="{!c.deleteSelected}" />
        <lightning:button variant="brand" label="Add New" onclick="{!c.addContactRole}" />
     </div>
    <table class="slds-table slds-table_bordered slds-table_striped">
        <thead>
            <tr class="slds-text-title_caps">
              <th scope="col" style="background-color : #ccc;" >
                   <div class="slds-truncate slds-align_absolute-center" >
                         <label class="slds-checkbox">
                            <!--header checkbox for select all-->
                            <ui:inputCheckbox aura:id="box3" change="{!c.selectAll}"/>
                            <span class="slds-checkbox--faux"></span>
                            <span class="slds-form-element__label text"></span>
                         </label>
                   </div>
              </th>
              <th scope="col" style="background-color : #ccc;" >
                <div class="slds-truncate slds-align_absolute-center" title="Type">Type</div>
              </th>
             <th scope="col" style="background-color : #ccc;">
                <div class="slds-truncate slds-align_absolute-center" title="Role">Role</div>
              </th>
            <th scope="col" style="background-color : #ccc;">
                <div class="slds-truncate slds-align_absolute-center" title="Product Family">Product Family</div>
              </th>
            <th scope="col" style="background-color : #ccc;">
                <div class="slds-truncate slds-align_absolute-center" title="Contact">Contact</div>
              </th>
            <th scope="col" style="background-color : #ccc;">
                <div class="slds-truncate slds-align_absolute-center" title="Product Account Contact">Product Account Contact</div>
              </th>
            </tr>
        </thead> 
    <tbody> 
   
        <aura:iteration items="{!v.relatedContactsRoles}" var="relatedContactsRole">
        <tr class="slds-text-title_caps">
          <td scope="col" class="slds-text-align--right" style="width:3.25rem;">
                  <div class="slds-form-element"> 
                     <div class="slds-form-element__control">
                        <label class="slds-checkbox">
                           <ui:inputCheckbox text="{!relatedContactsRole.Id}" aura:id="boxPack" value="" change="{!c.checkboxSelect}"/>
                           <span class="slds-checkbox--faux"></span>
                           <span class="slds-form-element__label text"></span>
                        </label>
                     </div>
                  </div>
          </td>
          <td scope="col">
            <div class="slds-truncate" title="Type">
                <ui:inputselect class="slds-input" value="{!relatedContactsRole.Type__c}" >
                    <ui:inputSelectOption text="Product" value="Product"/>
        		    <ui:inputSelectOption text="Functional" value="Functional"/>
                </ui:inputselect>
              </div>
          </td>
         <td scope="col">
            <div class="slds-truncate" title="Role">
                  <ui:inputSelect class="slds-input"  value="{!relatedContactsRole.Role__c}" >
                   <ui:inputSelectOption text="Primary CEO/President" value="Primary CEO/President"/>
                    <ui:inputSelectOption text="Primary Marketing" value="Primary Marketing"/>
                    <ui:inputSelectOption text="Primary Lending" value="Primary Lending"/>
                    <ui:inputSelectOption text="Lending" value="Lending"/>
                    <ui:inputSelectOption text="Primary HR" value="Primary HR"/>
                    <ui:inputSelectOption text="Primary Legal/Compliance" value="Primary Legal/Compliance"/>
                    <ui:inputSelectOption text="Primary Operations" value="Primary Operations"/>
                    <ui:inputSelectOption text="Primary Finance" value="Primary Finance"/>
                    <ui:inputSelectOption text="Primary Risk Manager" value="Primary Risk Manager"/>
                    <ui:inputSelectOption text="Primary Training" value="Primary Training"/>
                    <ui:inputSelectOption text="Primary IT" value="Primary IT"/>
                    <ui:inputSelectOption text="Primary Data" value="Primary Data"/>
                    <ui:inputSelectOption text="Primary Board Member" value="Primary Board Member"/>
                    <ui:inputSelectOption text="Board Member" value="Board Member"/>
                    <ui:inputSelectOption text="Primary Mortgage" value="Primary Mortgage"/>
                    <ui:inputSelectOption text="Primary Data" value="Primary Data"/>
                    <ui:inputSelectOption text="Mortgage" value="Mortgage"/>
                    <ui:inputSelectOption text="Primary Workers Compensation" value="Primary Workers Compensation"/>
                    <ui:inputSelectOption text="Owner" value="Owner"/>
                    <ui:inputSelectOption text="Stakeholder" value="Stakeholder"/> 
                </ui:inputSelect>
            </div>
          </td>
        <td scope="col">
            <div class="slds-truncate" title="Product Family">
                  <ui:inputSelect class="slds-input" value="{!relatedContactsRole.Product_Family__c}" >
                    <aura:iteration items="{!v.relatedProductFamilies}" var="relatedFamily" >
                        <ui:inputSelectOption text="{!relatedFamily.Name}" value="{!relatedFamily.Id}"/>
                    </aura:iteration>
                 </ui:inputSelect> 
            </div>
          </td>
        <td scope="col">
           <div class="slds-truncate" title="Contact">
                <ui:inputSelect class="slds-input"  value="{!relatedContactsRole.Contact__c}" >
                    <aura:iteration items="{!v.relatedContactsOfRoles}" var="relatedCon" >
                        <ui:inputSelectOption text="{!relatedCon.Name}" value="{!relatedCon.Id}"/>
                    </aura:iteration>
               </ui:inputSelect> 
            </div>
          </td>
        <td scope="col">
            <div class="slds-truncate" title="Primary Account Contact">
                <label class="slds-checkbox slds-align_absolute-center">
                    <ui:inputCheckbox value="{!relatedContactsRole.Primary__c}"/> 
                    <span class="slds-checkbox--faux" />
                    <span class="slds-form-element__label"></span>
                </label>
            </div>
          </td>
        </tr>
    </aura:iteration>
   
</tbody>
</table>
</div>