getRequest()->getParam('sitemap_id'); $sitemap = $this->_objectManager->create('Magento\Sitemap\Model\Sitemap'); /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ $sitemap->load($id); // if sitemap record exists if ($sitemap->getId()) { try { $sitemap->generateXml(); $this->messageManager->addSuccess( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) ); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We can\'t generate the sitemap right now.')); } } else { $this->messageManager->addError(__('We can\'t find a sitemap to generate.')); } // go to grid $this->_redirect('adminhtml/*/'); } }