Identity Class

Overview 

The Identity class is an immutable representation of a user’s identity within the Salesforce Marketing Cloud SDK. It encapsulates user identification information including profile ID, party identification details, and custom attributes.

Getting an Instance 

To obtain an Identity instance:

1SFMCSdk.requestSdk { sdk -> sdk.identity }

Updating Identity 

Two methods are available for updating identity:

  1. Kotlin DSL syntax (recommended for Kotlin) - using the edit function
  2. Builder pattern - for Java and Kotlin compatibility

Properties 

PropertyTypeDescription
profileIdString?Unique identifier for user profile (Marketing Cloud Engagement)
partyIdentificationNameString?User’s display name or full name (Mobile App Messaging)
partyIdentificationNumberString?Unique identifier number for user (Mobile App Messaging)
partyIdentificationTypeString?User’s category or classification (Mobile App Messaging)
attributesMap<String, String?>Custom attributes map (shared by both services)
registrationIdStringRegistration identifier

Nested Types 

Builder 

1class Builder

Provides a fluent API for setting identity properties and creating new Identity instances.

Functions 

edit 

1fun edit(editor: IdentityEditor.() -> Unit): Boolean

Kotlin DSL syntax for modifying Identity properties through an IdentityEditor.

Parameters:

  • editor: Lambda function providing DSL editing interface

Returns: Boolean indicating success of the edit operation


newBuilder 

1fun newBuilder(): Identity.Builder

Creates a new Builder instance initialized with current identity values, enabling modifications.

Returns: Identity.Builder instance for updating properties


toJson 

1fun toJson(): JSONObject

Serializes the Identity to a JSONObject representation, including platform, profile ID, installation ID, party identification details, and attributes.

Returns: JSONObject containing all identity properties


equals 

1open operator override fun equals(other: Any?): Boolean

Standard equality comparison implementation.


hashCode 

1open override fun hashCode(): Int

Standard hash code implementation.


toString 

1open override fun toString(): String

String representation of the identity.