How to call \Magento\Sales\Model\ResourceModel\Grid::refresh method

I am following this link: blog.sivaschenko.com

 namespace Vendor\OrderGridSync\Controller\Index;
 class Sync extends \Magento\Framework\App\Action\Action
protected $_pageFactory;
protected $_postFactory;

* @var \Magento\Sales\Model\ResourceModel\Grid[]

protected $grids;
 * @param array $grids
public function __construct(
        \Magento\Sales\Model\ResourceModel\Grid $grids,
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory            
        $this->grids = $grids;
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);            

public function execute()
     * Refresh grids list
     * @param int $orderId
     * @return $this
    foreach ($this->grids as $grid) {
     * @var \Magento\Sales\Model\ResourceModel\Grid[]
    $grid->refresh(81, "affiliate_information");


1 exception(s):
Exception #0 (BadMethodCallException): Missing required argument 
$mainTableName of Magento\Sales\Model\ResourceModel\Grid.

1 Answer 1


You need to specify the 3 required Params via Factory Creation Logic of Magento.

Something as follows Inject \Magento\Sales\Model\ResourceModel\GridFactory $gridInterface in the constructor and when you use it

                'mainTableName' => 'sales_order',
                'gridTableName' => 'sales_order_grid',
                'orderIdField' => 'entity_id',

This way you can give values to required params of constructor. The first param of Context Object is handled by Magento so that need not be given & in the same way other optional params can also be given a value.

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.