You do not create an entity on its own, since standard and custom objects are the entities. But you can reference one through an Entity Definition relationship on a custom metadata type, which lets a configuration record point at an object by metadata rather than by a typed-in name. Here is how to add that field in Setup.
- Open the custom metadata type
In Setup, go to Custom Metadata Types, then click Manage Records, or open the type definition. You add the relationship on the type, the same place you add any custom field to it.
- Add a Metadata Relationship field
Under Custom Fields, click New. Choose the Metadata Relationship field type. This is the only field type that can point at object or field metadata rather than storing plain data.
- Select Entity Definition as the target
When asked what the relationship points to, choose Entity Definition, described as the metadata of a standard or custom object. To target a single field instead, choose Field Definition, which resolves through EntityParticle.
- Name the field and save
Give the field a clear label and API name, set who can see it, then save. Each record of the type can now select which object it applies to from a metadata-backed lookup.
Points a custom metadata record at a standard or custom object. Resolves through EntityDefinition, so it survives renames better than a text field.
Points at one field on an object. Resolves through EntityParticle, for rules that must target a single column rather than a whole object.
A public custom metadata type cannot relate to a protected one. Decide visibility before wiring relationships, because it constrains what you can reference.
- You cannot create an entity from this screen. The relationship only references objects that already exist in the org.
- A public custom metadata type cannot be related to a protected custom metadata type, so plan visibility first.
- Read the related object in Apex through the relationship field, not by parsing a stored name string, so renames do not break your logic.