submissionFactory->create()->load((int)$this->getRequest()->getParam('entity_id')); if (!$submission->getId()) { throw new \RuntimeException('Submission not found.'); } $submission->delete(); $this->messageManager->addSuccessMessage(__('The contact message has been deleted.')); } catch (\Throwable $exception) { $this->messageManager->addErrorMessage(__('The contact message could not be deleted.')); } return $this->resultRedirectFactory->create()->setPath('*/*/'); } }