filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** * Execute action * * @return \Magento\Backend\Model\View\Result\Redirect */ public function execute() { $collection = $this->filter->getCollection($this->collectionFactory->create()); $accountsCount = 0; foreach ($collection->getItems() as $account) { $this->deleteObj($account); ++$accountsCount; } $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $accountsCount)); return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index'); } /** * Delete object. * * @param mixed $object * @return void */ private function deleteObj($object) { $object->delete(); } }