Create a custom facet
If you are using Sitecore XP 10.2 or later, you can also create facets using the Codeless Schema Extensions module.
This topic describes how to create a facet model named FrequentFlyerInfo and use it to define a contact facet with the same key.
Facet keys are case sensitive.
Create a facet model class
Create a facet model class
-
Create a class that inherits
Sitecore.XConnect.Facet -
Add one or more properties that adhere to xConnect’s type restrictions.
ImportantIf you are going to use your facet in the context of the tracker, it must be marked
[Serializable]. -
If necessary, use a constructor to indicate mandatory properties. In the following example,
FrequentFlyerIDis mandatory and has a private setter, which means it cannot be updated once it has been set:ImportantAll facets must declare an empty constructor - this is an oData restriction. The constructor can be private.
-
Decorate facet or facet properties with the
[PIISensitive]or[DoNotIndex]attributes as necessary. For example, a contact’s passport number is PII data: -
Optionally, use the
[FacetKey]attribute to define a default facet key. Default facet keys simplify usage of the xConnect Client API.
Sitecore’s default facet keys are in a static class named Sitecore.XConnect.Collection.Model.CollectionModel.FacetKeys, alongside the core collection model.
Define a custom facet in the model
Define a custom facet in the model
Define the new facet in your collection model using the .DefineFacet() method. In the following example, the facet has been added to a model named SampleModel. If you are using the model in a Sitecore context, the model class must be added to the client configuration file.
If you do not register your facet, you cannot use it. You will get errors such as ‘The type of this instance does not correspond to any type in the schema’.
Use custom facets
Use custom facets
Use the xConnect Client API to work with facets.
Sitecore ships with a number of built-in facets.