I want to generate PDF of selected orders, Rest of the functionality is complete just wanted to get selected Ids from sales order grid. For now I am getting full list of Orders on clicking my custom action. I am passing Order collection to controller action from custom block. This is what I wanted to get in block: enter image description here

My Block Class is:

class Order extends \Magento\Framework\View\Element\Template {

public function __construct(\Magento\Framework\View\Element\Template\Context $context,
                          \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
                          \Magento\Sales\Model\OrderRepository $orderRepository
                          array $data = []
) {

parent::__construct($context, $data);        
public function getOrders() {
        //$ids = '24,23,21,16';
        $orderCollection = $this->_orderCollectionFactory->create()->addFieldToSelect('*');
        //$orderCollection = $orderCollection->addFieldToFilter('entity_id', ['in' => $ids]);
        return $orderCollection;

And Controller is: use VendorName\ModuleName\Block\Order;

class CreatePdf extends \Magento\Backend\App\Action  {
public function __construct(Context $context,Order $order, DirectoryList $dir, PageFactory $resultPageFactory)


public function execute() {

    //Custom Logic

I followed this link but it is not working, https://stackoverflow.com/questions/24884544/how-can-i-get-the-selected-order-ids-in-custom-action-in-sales-order-on-click


1 Answer 1


Got the solution by using this class:


as used here: Magento2 Mass Action to Sales Order Grid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.