/** * @param AbstractCollection $collection * @return \Magento\Backend\Model\View\Result\Redirect */ protected function massAction(AbstractCollection $collection) { $customersDeleted = 0; foreach ($collection->getAllIds() as $customerId) { $this->customerRepository->deleteById($customerId); $customersDeleted++; } if ($customersDeleted) { $this->messageManager->addSuccess(__('A total of %1 record(s) were deleted.', $customersDeleted)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath($this->getComponentRefererUrl()); return $resultRedirect; }