Update product attribute value programmatically in Magento 2 .
<?php
namespace VendoreModuleHelper;
use MagentoCatalogModelProductAction as ProductAction;
use MagentoCatalogModelResourceModelProductCollectionFactory;
use MagentoFrameworkAppHelperAbstractHelper;
use MagentoFrameworkAppHelperContext;
use MagentoStoreModelStoreManagerInterface;
class Data extends AbstractHelper
{
protected $messageManager;
private $productCollection;
private $productAction;
private $storeManager;
public function __construct(
Context $context,
CollectionFactory $collection,
ProductAction $action,
StoreManagerInterface $storeManager
)
{
$this->productCollection = $collection;
$this->productAction = $action;
$this->storeManager = $storeManager;
parent::__construct($context);
}
public function setcustomAttributeData($param)
{
try {
$collection = $this->productCollection->create()->addFieldToFilter('*');
$storeId = $this->storeManager->getStore()->getId();
$ids = [];
$i = 0;
foreach ($collection as $item) {
$ids[$i] = $item->getEntityId();
$i++;
}
$this->productAction->updateAttributes($ids, array('attribute' => $param), $storeId);
} catch (Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
}

