'Invalid Value provided for RegionId field in Magento 2

I am getting this error while the controller run -'Invalid value of "491" provided for the regionId field.'. I want to transfer the telephone number from the billing address to the customer mobile number field and for that I have built this controller

Error for RegionId

My controller code is :

<?php

namespace [Vendor]\[Extension]\Controller\Adminhtml\Index;

use [Vendor]\[Extension]\Helper\Data;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;

class Update extends Action
{
    protected $_customerRepoInterface;
    protected $_customerFactory;
    public function __construct(
         Context $context,
         Data $helper,
         JsonFactory $resultJsonFactory,                                    
         \Magento\Customer\Api\CustomerRepositoryInterface $customerRepoInterface,
         \Magento\Customer\Model\CustomerFactory $customerFactory
    )
    {
        $this->resultJsonFactory = $resultJsonFactory;
        $this->helper = $helper;
        $this->_customerRepoInterface = $customerRepoInterface;
        $this->_customerFactory = $customerFactory;
        parent::__construct($context);
    }
    public function execute()
    {
        $result = $this->resultJsonFactory->create();

        $customerCollectoin = $this->_customerFactory->create()->getCollection()
            ->addAttributeToSelect("*")
            ->load();
        foreach ($customerCollectoin as $customer){

            if($customer->getPrimaryBillingAddress()) {
                if ($customer->getPrimaryBillingAddress()->getTelephone()) {
                    $telephone = $customer->getPrimaryBillingAddress()->getTelephone();
                    $customerObj = $this->_customerRepoInterface->getById($customer->getId());
                    $customerObj->setCustomAttribute('mobilenumber', $telephone);
                    $this->_customerRepoInterface->save($customerObj);
                }
            }
        }


        return $result->setData( count($customerCollectoin));
    }
    protected function _isAllowed()
    {
        return true;
    }
}

~~Thank you in advance! enter code here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source