0

I'm basically trying to re Render the page after the delete button is hit so that the user doesn't incounters and error message saying that the record was already deleted.

The table functionality is working fine. I just want to reRender the page after the records are deleted.

enter image description here

VF PAGE:

<apex:page controller="CarController" showHeader="false" standardStylesheets="false" applyBodyTag="false" docType="html-5.0">
  <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en">
    <head>
      <meta charset="utf-8" />
      <meta http-equiv="x-ua-compatible" content="ie=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1" />
      <title>Cars</title>
      <apex:slds />
    </head>
    <body class="slds-scope">
      <div class="slds-grid slds-wrap">
        <div class="slds-col slds-size_1-of-1 slds-medium-size_1-of-2 slds-large-size_1-of-3">
          <div class="slds-card">
            <div class="slds-card__header slds-grid">
              <div class="slds-media slds-media_center">
                <div class="slds-media__figure">
                  <svg class="slds-icon slds-icon-standard-car" aria-hidden="true">
                    <use xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#car" />
                  </svg>
                </div>
                <div class="slds-media__body">
                  <h2 class="slds-card__header-title slds-truncate" title="Cars">Cars</h2>
                </div>
              </div>
            </div>
            <div class="slds-card__body">
              <apex:form>
                <table id="table2" class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_striped">
                  <thead>
                    <tr class="slds-line-height_reset">
                      <th scope="col">
                        <div class="slds-truncate" title="Select"></div>
                      </th>
                      <th scope="col">
                        <div class="slds-truncate" title="Name">Name</div>
                      </th>
                                              <th scope="col">
                        <div class="slds-truncate" title="Year">Year</div>
                      </th>
                      <th scope="col">
                        <div class="slds-truncate" title="Make">Make</div>
                      </th>
                      <th scope="col">
                        <div class="slds-truncate" title="Model">Model</div>
                      </th>
                    </tr>
                  </thead>
                  <tbody>
                    <apex:repeat value="{!cars}" var="car">
                      <tr>
                        <td>
                          <apex:inputCheckbox value="{!car.Selected__c}" />
                        </td>
                        <td>
                          <div class="slds-truncate" title="{!car.Name}">{!car.Name}</div>
                        </td>
                      </tr>
                    </apex:repeat>
                  </tbody>
                </table>
                <apex:commandButton value="Delete Selected" action="{!deleteSelected}" reRender="table2" />
              </apex:form>
            </div>
          </div>
        </div>
      </div>
    </body>
  </html>
</apex:page>

                   
  

APEX CONTROLLER:

public class CarController {
  public List<Auto__c> cars {get; set;}

  public CarController() {
    cars = [SELECT Name, Selected__c FROM Auto__c];
  }

  public void deleteSelected() {
    List<Auto__c> carsToDelete = new List<Auto__c>();
    for (Auto__c car : cars) {
      if (car.Selected__c) {
        carsToDelete.add(car);
      }
    }
    delete carsToDelete;
  }
}

1 Answer 1

0

First you can wrap your table element in apex:outputpanel tag(i dont thing html tags can be reRender directly)

<apex:outputPanel>
<table id="table2" class="slds-table slds-table_bordered slds-table_cell-buffer slds-table_striped">
.
.
 </table>
</apex:outputPanel>

Second, you will have to reassign cars after deletion of element

  public void deleteSelected() {
    List<Account> carsToDelete = new List<Account>();
    for (Account car : cars) {
      if (car.Selected__c) {
        carsToDelete.add(car);
      }
    }
    delete carsToDelete;
      cars = [SELECT Name, Selected__c FROM Account];
  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .