Many times, there is a need to create custom fields on objects for storing project specific custom data. We can create custom fields on any Salesforce B2B Commerce Cloud (preiously CloudCraze) custom objects. However, the steps below need to be followed in order to expose those fields on CC model and to be used on UI level when pages are rendered on storefront.
Custom field for regular or header objects
Objects like Product, Cart, Order are header objects and we can use applicable service class to extend and pull in the custom fields to Salesforce B2B Commerce Cloud model.
Custom field for iterative objects
Object like Cart Items, Order Items etc. are used for showing information about all items in the cart or order. There is no direct service class for these objects. In order to add new custom fields, we have to extract the subquery and update that using header object service class.
Use ccLog query parameter to generate CC logs in the browser console. Extract the field subquery from there that will be used in the service class.
Below is an example of service class extension to use the extracted subquery and add other custom fields for CC model.
Using the service class extension
After creating the service class extension code, they need to be called and associated appropriately in CC Admin Service Management. The classes need to be set with “c.” prefix. This will allow Salesforce B2B Commerce Cloud to read these custom fields for further usage. These will appear in base CC data model for appropriate objects and can be read on the VF handlebar overrides.