Every time I need to clear cache when saving customer attributes using the following code.

$customerData->setCustomAttribute('custom_name', $name); $customermodel->updateData($customerData);

what is the proper solution to save customer custom attributes in Magento2?

1 Answer 1


use Factory and try the following code

$customerData->setCustomAttribute('custom_name', $name);            
$customerModel = $this->customerFactory->create()->updateData(
  • I tried this way but still need to clear cache $customerFactory= $ob->create('Magento\Customer\Model\CustomerFactory'); $customerData->setCustomAttribute('custom_name', $name); $customerModel = $customerFactory->create()->updateData( $customerData ); $customerResource = $objectManager->create ('\Magento\Customer\Model\ResourceModel\CustomerFactory')->create(); $customerResource->saveAttribute($customerModel, 'custom_name');
    – Vamsi
    Jul 12, 2018 at 13:44

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.