---
title: "Accessing facets in session"
slug: "accessing-facets-in-session"
abstract: "How to access contact facets that have been loaded into session from xConnect."
---
# Accessing facets in session

When a visitor returns to your site, a configurable list of facets are [loaded into session](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/load-facets-into-session.html "Load facets into session") from xConnect.

> [!important]
> You can edit facets that are loaded into session, but they are not automatically saved to xConnect on session end. You must [use the xConnect Client API to update facets](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/set-contact-facets-in-session.html "Set contact facets in session").

## Access the IXConnectFacets class in session

The `IXConnectFacets` tracker facet inherits `Sitecore.Analytics.Model.Framework.IFacet` and contains a dictionary of xConnect facets that inherit `Sitecore.XConnect.Facet`. [Configuration](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/load-facets-into-session.html "Load facets into session") determines which facets are loaded into the facets dictionary. The following example demonstrates how to access the `PersonalInformation` facet, which is available by default:

```csharp
var xConnectFacet = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<Sitecore.Analytics.XConnect.Facets.IXConnectFacets>("XConnectFacets");

PersonalInformation personal = xConnectFacet.Facets[PersonalInformation.DefaultFacetKey] as PersonalInformation;

```

## Access legacy facet classes in session

In addition to the `IXConnectFacets` facet, a number of legacy facet classes are populated at the start of the session. This means that some facet data is available in two locations. The following table lists all legacy facets that are loaded into session and their corresponding xConnect facet:

| **Legacy Facet** | **Matching entry in**`IXConnectFacets` |
| --- | --- |
| `IContactPersonalInfo` | `PersonalInformation` (`PersonalInformation.DefaultFacetKey`) |
| `IContactAddresses` | `AddressList` (`AddressList.DefaultFacetKey`) |
| `IContactEmailAddresses` | `EmailAddressList` (`EmailAddressList.DefaultFacetKey`) |
| `IContactPhoneNumbers` | `PhoneNumberList` (`PhoneNumberList.DefaultFacetKey`) |
| `IContactPicture` | `Avatar` (`Avatar.DefaultFacetKey`) |
| `IContactCommunicationProfile` | `ConsentInformation` (`ConsentInformation.DefaultFacetKey`) |
| `IContactPreferences` | `PersonalInformation` (`PersonalInformation.DefaultFacetKey`) |

The following example demonstrates how to access the legacy `IContactPersonalInfo` facet:

```text
IContactPersonalInfo personal = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<Sitecore.Analytics.Model.Entities.IContactPersonalInfo>("Personal");

```

The following example demonstrates how to access the data represented by the `IContactPersonalInfo` facet via the newer `IXConnectFacets` facet:

```csharp
var xConnectFacet = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<Sitecore.Analytics.XConnect.Facets.IXConnectFacets>("XConnectFacets");

var allFacets = xConnectFacet.Facets;

PersonalInformation personalInfo = allFacets[PersonalInformation.DefaultFacetKey] as PersonalInformation;

```

## Access the key behavior cache facet in session

The following example demonstrates how to access the [key behavior cache](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/key-behavior-cache.html "Key behavior cache"):

```csharp
var xConnectFacets = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<IXConnectFacets>("XConnectFacets");

KeyBehaviorCache kbc = xConnectFacets.Facets[KeyBehaviorCache.DefaultFacetKey] as KeyBehaviorCache;
var recentCampaigns = kbc.Campaigns;

```

> [!tip]
> Each key behavior cache entry has a `DefinitionId` property. Use the [Marketing Operations API](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/marketing-operations-api.html "Marketing Operations API") to retrieve definition items by ID.

## Access the contact behavior profile facet in session

The following example demonstrates how to access the contact behavior profile:

```csharp
var xConnectFacets = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<IXConnectFacets>("XConnectFacets");

ContactBehaviorProfile cbp = xConnectFacets.Facets[ContactBehaviorProfile.DefaultFacetKey] as ContactBehaviorProfile;
var matchedProfileIDs = cbp.Scores.Select(x => x.Value.ProfileDefinitionId);

```

## Access automation plan enrollments in session

The following example demonstrates how to access a contact’s automation activities:

```csharp
var xConnectFacets = Sitecore.Analytics.Tracker.Current.Contact.GetFacet<IXConnectFacets>("XConnectFacets");

AutomationPlanEnrollmentCache enrolments = xConnectFacets.Facets[AutomationPlanEnrollmentCache.DefaultFacetKey] as AutomationPlanEnrollmentCache;

var specificActivityEnrolments = enrolments.ActivityEnrollments.Where(x => x.ActivityId == Guid.Parse("9098fa76-eaf3-4adc-ada5-e46014ba9f30"));
var specificPlanEnrolments = enrolments.ActivityEnrollments.Where(x => x.AutomationPlanDefinitionId == Guid.Parse("6ce0925e-961e-469e-b085-454a6ba0a931"));

```

> [!tip]
> Each automation plan enrollment cache entry has a plan definition ID and an activity ID. Use the Automation Plan Definition manager to retrieve the plan definition item. Use the [Activity Descriptor Locator API](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/activity-type-descriptors.html "Activity type descriptors") to retrieve activity descriptors by ID.