I have the class below working at my end. In other words, way 2 is the way to go but this is assuming your custom attribute has the right setup. Also, you may notice below I am setting the area code to adminhtml
class SaveProductAttribute extends Command { /** * @var ProductRepositoryInterface */ private $productRepository; /** * @var \Magento\Framework\App\State */ private $state; public function __construct( ProductRepositoryInterface $productRepository, \Magento\Framework\App\State $state, $name = null) { parent::__construct($name); $this->productRepository = $productRepository; $this->state = $state; } public function configure() { $this->setName('mbs:product_multiselect:save') ->setDescription('Save product multiselect value'); $this->addArgument('sku', InputArgument::REQUIRED); } protected function execute(InputInterface $input, OutputInterface $output) { $this->initialiseAreaCode(); $product = $this->productRepository->get($input->getArgument('sku')); $output->writeln(sprintf('sku: %s has activity: %s', $input->getArgument('sku'), $product->getData('activity')) ); $product->setData('activity', [5432]); $this->productRepository->save($product); $output->writeln('attribute saved'); } private function initialiseAreaCode(): void { try { $this->state->setAreaCode(Area::AREA_ADMINHTML); } catch (\Exception $e) { } }