Linking CMS images and attachments to product records
Key Takeaway
A ProductMedia record links a product to CMS content, and its media group sets what the media is for, such as the listing image.
In a B2B Commerce store, product images and attachments are linked to products through ProductMedia records. Each record points to a Product2 record and to Salesforce CMS content. The store reads that content through a channel to the CMS workspace. You can create these links one product at a time in the store, in bulk with a CSV product import, or through the API. These links matter because they connect a product to the images and attachments the store shows for it.
How a product links to its media
ProductMedia, available in API version 49.0 and later, is the object that adds rich media, including images and attachments, to a product. Think of a ProductMedia record as a connector between a product and CMS content. Its fields hold the details:
ProductIdis a lookup toProduct2, so it names the product.ElectronicMediaIdis a polymorphic lookup toManagedContentorManagedContentInfo, so the media it points to is CMS content.ElectronicMediaGroupIdis a lookup toElectronicMediaGroup, so it names the media group.SortOrdersets the order the media is displayed in.
ProductMedia supports create(), update(), upsert(), delete(), and query(), so an integration can link media to products through the API. ProductMediaChangeEvent (API version 57.0) provides change events. Field history is available for tracked fields. Sharing rules are available for the object.
ProductMedia belongs to the Product and Category Media data model, which connects products and categories to images and other attachments. The model's objects include Product2, ProductCategory, ProductMedia, ProductCategoryMedia, ElectronicMediaUse, ElectronicMediaGroup, and ManagedContentInfo. These objects require a B2B Commerce license. To access product media, a user needs the B2B Commerce license and a CMS workspace.