cancel
Showing results for 
Search instead for 
Did you mean: 

Type Error occurred when creating object:

Re: Type Error occurred when creating object:

Hi @Shoaib967 ,

 

Can you please try replacing your mass action node with follow and try to run all deployment commands.

 

<massaction name="listing_massaction">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
               <item name="selectProvider" xsi:type="string">components_listing.components_listing.components_columns.ids</item>
               <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
               <item name="indexField" xsi:type="string">component_id</item>
            </item>
        </argument>
        <action name="delete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">delete</item>
                    <item name="label" xsi:type="string" translate="true">Delete</item>
                    <item name="url" xsi:type="url" path="*/*/massDelete"/>
                    <item name="confirm" xsi:type="array">
                      <item name="title" xsi:type="string" translate="true">Delete</item>
                      <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                  </item>
              </item>
          </argument>
      </action>
  </massaction>

Try to replace the bold one entries with your appropriate values.

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

Re: Type Error occurred when creating object:

Thanks @Nishu Jindal for the response, but sadly it is not working fine

Here is the GIT REPO if you can check it on your local?

Front end URL: /testimonial/index/add
https://github.com/shoaibgits/Testimonial

Re: Type Error occurred when creating object:

Hi @brasithaan45c7 , thnks for your time.

you can check the GIT Respository here: https://github.com/shoaibgits/Testimonial

Re: Type Error occurred when creating object:

Hi @Shoaib967 ,

 

I have checked the code and found that there are some issues in the code.

I have modified one file in your module and added one new file and now mass delete is working fine.

 

1.  Modified: app/code/Apriljune/Testimonial/etc/di.xml (Commented the rest code)

<type name="Apriljune\Testimonial\Model\ResourceModel\Testimonial\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">apriljune_testimonial</argument>
            <argument name="eventPrefix" xsi:type="string">test_grid_collection</argument>
            <argument name="eventObject" xsi:type="string">test_grid_collection</argument>
            <argument name="resourceModel" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial</argument>
        </arguments>
    </type>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="apriljune_testimonial_testimonial_listing_data_source" xsi:type="string">Apriljune\Testimonial\Model\ResourceModel\Testimonial\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

2. Added:  app/code/Apriljune/Testimonial/Model/ResourceModel/Testimonial/Grid/Collection.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Apriljune\Testimonial\Model\ResourceModel\Testimonial\Grid;

use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection as TestimonialCollection;

/**
 * Class Collection
 * Collection for displaying grid of sales documents
 */
class Collection extends TestimonialCollection implements SearchResultInterface
{
    /**
     * @var AggregationInterface
     */
    protected $aggregations;

    /**
     * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
     * @param \Magento\Framework\Event\ManagerInterface $eventManager
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
     * @param mixed|null $mainTable
     * @param string $eventPrefix
     * @param mixed $eventObject
     * @param mixed $resourceModel
     * @param string $model
     * @param null $connection
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
     *
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }

    /**
     * @return AggregationInterface
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

    /**
     * @param AggregationInterface $aggregations
     * @return $this
     */
    public function setAggregations($aggregations)
    {
        $this->aggregations = $aggregations;
        return $this;
    }

    /**
     * Get search criteria.
     *
     * @return \Magento\Framework\Api\SearchCriteriaInterface|null
     */
    public function getSearchCriteria()
    {
        return null;
    }

    /**
     * Set search criteria.
     *
     * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
    {
        return $this;
    }

    /**
     * Get total count.
     *
     * @return int
     */
    public function getTotalCount()
    {
        return $this->getSize();
    }

    /**
     * Set total count.
     *
     * @param int $totalCount
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setTotalCount($totalCount)
    {
        return $this;
    }

    /**
     * Set items list.
     *
     * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setItems(array $items = null)
    {
        return $this;
    }
}

Run the setup:di: compile command after deleting the generated/* folder.

Now mass delete is working fine.

 

Hope this helps you!

Problem Solved! Click Kudos & Accept as Solution!

Re: Type Error occurred when creating object:

Hello Shoaib967,

 

This error says something is wrong when creating an object. Generally, this error is when you've passed arguments from the calling method but do not receive those arguments in the called function.

 

However, removing that folder every time is risky, which may lead to data loss. So, therefore, you can follow the steps below to fix the error,

 

  • You must execute the following commands in your store's command line:

 

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

 

  • Lastly, run the below command,
chmod -R 777 var generated

Thus, implementing the above solution helps you to fix the "Type Error occurred when creating an object."

 

-----------------------------

Regards,

Rex M

Re: Type Error occurred when creating object:


@Shoaib967 wrote:
I am having the massaction "delete" in the ui_component and it is then process by a controller MassDelete in my adminhtml folder cg 125 price in pakistan.

like this:

<?php

namespace Apriljune\Testimonial\Controller\Adminhtml\Testimonial;

use Exception;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
use Magento\Backend\App\Action\Context;
use Apriljune\Testimonial\Model\ResourceModel\Testimonial\Collection as Testimonial;

/**
* Class MassDelete
*
* @package Apriljune\Testimonial\Controller\Adminhtml\Testimonial
*/
class MassDelete extends Action
{

   /**
    * @var Testimonial
    */
   protected $testimonial;


   /**
    * @param Context $context
    * @param Testimonial $testimonial
    */
   public function __construct( Context $context, Testimonial $testimonial )
   {
       parent::__construct($context);
       $this->testimonial = $testimonial;
   }

   /**
    * Execute action
    *
    * @return \Magento\Backend\Model\View\Result\Redirect
    */
   public function execute()
   {
       $selectedIds = $this->getRequest()->getParams()['selected'];
       if (!is_array($selectedIds)) {
           $this->messageManager->addErrorMessage(__('Please select one or more testimonial.'));
       } else {
           try {
               $collectionSize = count($selectedIds);
               foreach ($selectedIds as $_id) {
                   $testimonial = $this->testimonial->getItems()[$_id];
                   $testimonial->delete();
               }
               $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
           } catch (Exception $e) {
               $this->messageManager->addErrorMessage($e->getMessage());
           }
       }

       /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
       $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
       return $resultRedirect->setPath('*/*/');
   }
}

and massaction is like this in ui-component

<massaction name="listing_massaction">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/tree-massactions</item>
            </item>
        </argument>
        <action name="delete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">delete</item>
                    <item name="label" xsi:type="string" translate="true">Delete</item>
                    <item name="url" xsi:type="url" path="*/*/MassDelete"/>
                    <item name="confirm" xsi:type="array">
                      <item name="title" xsi:type="string" translate="true">Delete</item>
                      <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                  </item>
              </item>
          </argument>
      </action>
  </massaction>

Now when i select any row and delete it it redirect to the error page and show the exception

Type Error occurred when creating object: Apriljune\Testimonial\Controller\Adminhtml\Testimonial\MassDelete\Interceptor

i have already tried the solutions,

already done with this process as well

rm -rf var/di/* pub/static/* generated/*
rm -rf var/cache/* var/view_preprocessed/* 

bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy
bin/magento cache:flush

Interceptor is already create in /generated i have checked it.

But still the error is there any hint why it is showing error? any typo or logical error? BTW i am using 2.3.3 version of Magento


I also got same type of error but your thread help me somehow i add css and got resolved issue.