ContextDefinition defines the node relationships, attributes, identifiers, and data mappings used by runtime context instances. It contains a versioned model that connects context nodes and attributes to objects or other context definitions. It describes the structure and data connections, not the runtime context data itself.
Version activation, default mappings, cache retention, and persistence are separate controls. A definition can contain an inactive version, a mapping marked as default, and attributes excluded from persistence without those settings changing one another.
Key Elements
Several element names occur at different levels. The scope described below matters, especially for title and inheritedFrom.
| Element | What the Element Controls |
|---|---|
fullName, title, masterLabel
|
fullName is the metadata component identity. Definition-level title is the required name; masterLabel is the required user-facing label. They are separate fields. |
contextDefinitionVersions |
Contains versions, each with its own contextNodes and contextMappings. Each version requires an integer versionNumber. |
isActive, startDate, endDate
|
Control version activation and effective dates. startDate is required; isActive defaults to false. Only one version can be active at a time. |
contextTtl |
Controls how long data loaded into runtime context instances remains in cache. The default is 10 minutes. |
transient |
At the attribute level, true excludes the attribute from context persistence. The default is false. |
dataType |
Required attribute value type. Allowed values are boolean, currency, date, datetime, number, percent, picklist, reference, selfreference, and string. |
fieldType, domainSet
|
fieldType is required and accepts aggregate, input, inputoutput, or output. The separate domainSet field lists node references expressing parent-child relationships. |
contextTags, contextNodeAttrDictionaries
|
Tags provide shorthand identifiers for nodes or attributes. Dictionary associations contain required contextAttrDictIdentifier and contextNodeTagPrefix values and can appear on nodes and node mappings. |
contextMappings, contextMappingIntents, default
|
A version's mappings connect the model to data sources or destinations. Each intent requires mappingIntent, with values hydration, association, persistence, or translation. Mapping-level default defaults to false. |
contextNodeMappings |
Connects contextNode to an object or, for an existing context-to-context mapping, to mappedContextDefinition. |
contextAttributeMappings |
Connects contextAttribute to the required contextInputAttributeName and can contain hydration details. |
contextAttrHydrationDetails, ctxAttrHydrationCtxs
|
Describe hydration, meaning loading data into a context. Object hydration requires objectName and queryAttribute. Context-to-context hydration requires contextQueryAttribute. |
canBeReferenceDefinition, contextDefinitionReferences
|
canBeReferenceDefinition controls whether other definitions can refer to this definition and defaults to false. Each explicit reference requires referenceContextDefinition, which accepts an ID or name. |
inheritedFrom, inheritedFromVersion, clonedFrom
|
Record derivation and cloning origins. At definition level, these identify the parent definition, the parent version used for derivation, and the definition used for cloning. Nested inheritedFrom values have their own scopes. |
isProtected |
An auto-generated value that does not affect this metadata type's behavior. It is not an access-control setting. |
Behavior and Constraints
Access requires an organization preference. The organization must have ContextDefinitionsEnabled enabled to access this metadata type. Setting isProtected does not provide or restrict that access.
Activation belongs to a version. Read isActive together with startDate and endDate. The required startDate identifies when the version becomes active; endDate identifies when it becomes inactive. Merely including a version does not establish that it is active, because isActive defaults to false. A mapping's default flag selects a default mapping for that version; it does not activate the version.
Cache retention is not persistence. contextTtl applies to data held in the runtime context cache. It is separate from version effective dates and from persistence, which saves context data. At attribute level, transient=true skips the attribute during persistence; its default is false.
Nodes define structure, while attributes describe their values and relationships. Nodes can form a hierarchy, with attribute-level domainSet values listing node references for parent-child relationships. A node's transposable flag permits its data to be converted to field names. Attribute-level key and value flags separately identify key attributes and attributes serving as values within a node. All three flags default to false.
Identifiers have different scopes. A contextTags entry provides a unique shorthand identifier instead of a fully qualified tag structure name. Within a dictionary association, contextAttrDictIdentifier is the context attribute dictionary's developer name, while contextNodeTagPrefix is the prefix used to create the parent context node's unique identifier. A dictionary developer name, node tag prefix, and metadata component name are not interchangeable.
Hydration has two distinct paths. Object hydration uses Salesforce Object Query Language (SOQL) details under contextAttrHydrationDetails, including objectName and queryAttribute. These details can contain further nested contextAttrHydrationDetails. Context-to-context hydration instead uses ctxAttrHydrationCtxs, whose contextQueryAttribute identifies the source attribute in a context definition.
References, mappings, and lineage serve different purposes. An explicit referenceContextDefinition accepts either the referenced definition's ID or its name. By contrast, mappedContextDefinition identifies an existing context-to-context mapping target by API name. A record ID must not be treated as an API name.
At definition level, inheritedFrom names the parent definition, and inheritedFromVersion identifies the parent version used for derivation. That parent version is separate from the current definition's contained versionNumber values. clonedFrom names the definition used for cloning.
Mappings, node mappings, attribute mappings, nodes, attributes, tags, and hydration details can record their own inheritedFrom lineage. In a ContextDefinitionReference entry specifically, inheritedFrom is the ID of the parent reference, not the parent definition's name. These origin fields do not by themselves establish automatic synchronization with the source definition.
Deployment and Retrieval
ContextDefinition components are stored in the contextDefinitions directory with the .contextDefinition suffix. The type extends Metadata and inherits fullName. Use that component identity as the member name under ContextDefinition in package.xml, rather than substituting the definition's title or masterLabel.
The type supports the * wildcard in the manifest. See Deploying and Retrieving Metadata with the Zip File for manifest-based operations. Versions, nodes, attributes, mappings, tags, and hydration details are nested within the component; they are not separate ContextDefinition deployment members.
Deployment scope depends on the serialized references and what already exists in the destination. Check object mappings, hydration objects and fields, explicitly referenced definitions, context-to-context mapping targets, and dictionary identifiers. The destination must also have ContextDefinitionsEnabled enabled.
The documented manifest example includes CustomObject member CustomAccount__c and CustomField member Account.CustomAccountName__c alongside the definition. Those are dependencies of the example, not a required component list for every definition. The available mapping structures do not mean that every possible related component must be included.
Incoming references also affect change assessment. A manufacturing program template, an orchestration plan context mapping, or associated translation metadata can point to a definition. Such a connection does not by itself prove active runtime use or establish a mandatory deployment sequence.
Relationships
Definitions can connect to other definitions through explicit references and context-to-context mappings. Object mappings and hydration details connect the context model to object and field metadata. The connections below describe possible dependencies, not proof that a particular definition uses them.
References
-
ContextDefinition:referenceContextDefinitionfor an explicit reference by ID or name;mappedContextDefinitionfor a context-to-context mapping target by API name. -
CustomObject:objecton node mappings andobjectNameon hydration details identify mapped or queried objects. -
CustomField:queryAttribute, interpreted withobjectName, can identify a custom field used for hydration, as in the documented example.
Lineage associations are separate from data mappings: definition-level inheritedFrom and clonedFrom name origin definitions, while inheritedFromVersion identifies the derivation's parent version. Dictionary associations use contextAttrDictIdentifier and contextNodeTagPrefix on nodes or node mappings.
Referenced By
-
MfgProgramTemplate:contextDefinition. -
OrchestrationPlanCtxMapping:contextDefinition. -
Translations:nameentries.
Documentation Inconsistencies
queryAttribute is described as a SOQL query, but the documented examples contain attribute names such as Name and CustomAccountName__c, rather than complete SELECT statements. Do not assume that every serialized queryAttribute value is a complete SOQL statement.
The description of fieldType repeats wording about node references, while its allowed values are aggregate, input, inputoutput, and output. The separate domainSet element holds the node references used to express parent-child relationships.
Common Questions
How do I retrieve a ContextDefinition?
Include its fullName as a member of type ContextDefinition in package.xml, or use the supported * wildcard. Files use the .contextDefinition suffix in contextDefinitions. Access requires ContextDefinitionsEnabled.
Does a default mapping make a context definition version active?
No. Mapping-level default selects a default mapping for the version. Version activation uses isActive, startDate, and endDate. Only one version can be active at a time.
Does contextTtl control whether an attribute is persisted?
No. contextTtl controls runtime cache retention and defaults to 10 minutes. Attribute-level transient=true excludes that attribute from persistence. Neither setting controls version effective dates.
What is the difference between referenceContextDefinition and mappedContextDefinition?
referenceContextDefinition stores an explicit reference and accepts an ID or name. mappedContextDefinition identifies an existing context-to-context mapping target by API name. They are distinct mechanisms.
Which dependencies should I include when deploying a ContextDefinition?
Include dependencies required by the actual serialized mappings and references that are not already available in the destination. These can involve objects, hydration fields, other definitions, and dictionary associations. The example manifest's object and field entries are not a universal checklist.