Magento, Magento 2, Magento basic, Magento Database

Hot to Get Color hex code value for product in Magento2:

Using below script we can able to get the product Hex code in magento2

$product_id = 1000;
try{
$objectMansager = \Magento\Framework\App\ObjectManager::getInstance(); 
$productObj = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id); 
$colorOption = $productObj->getResource()->getAttribute('color')->getFrontend()->getValue($productObj); 
$colorOptionId = $product->getResource()->getAttribute('color')->getOptionId($colorOption); 
$attr = $productObj->getResource()->getAttribute('color'); 
$simpleProductHexCode = ''; 
if ($attr->usesSource()) {
 $attributeId = $attr->getSource()->getOptionId($colorOption); 
$resource = $objectMansager->get('Magento\Framework\App\ResourceConnection'); 
$connection = $resource->getConnection(); 
$tableName = $resource->getTableName('eav_attribute_option_swatch');
$sql = "Select * FROM " . $tableName." where option_id = ".$attributeId; 
$result_query = $connection->fetchAll($sql); 
echo $productHexCode = $result_query[0]['value']; 
}
}catch(Exception $e){}