Personalization Class
Get assigned personalization audiences that match the user context. Create, get, update, and delete an audience. Get personalization targets that match the user context, based on the assigned audiences that include the user. Create and update targets. Get and delete a target.
Personalization varies what the user can see in the browser but doesn’t secure data in any way. To prevent users accessing sensitive data, use standard Salesforce security features, such as sharing rules and permission sets.
These methods are for Personalization. All methods are static.
-
createAudience(communityId, audience)
Create an audience.
-
createTargets(communityId, target)
Create targets.
-
deleteAudience(communityId, audienceId)
Delete an audience.
-
deleteTarget(communityId, targetId)
Delete a target.
-
getAudience(communityId, audienceId, includeAudienceCriteria)
Get an audience.
-
getAudienceBatch(communityId, audienceIds)
Get audience information for a comma-separated list of audience IDs.
-
Get a list of assigned audiences that match the user context and record information.
-
Get a list of assigned audiences that match the user context.
-
getTarget(communityId, targetId)
Get a target.
-
getTargetBatch(communityId, targetIds)
Get target information for a comma-separated list of target IDs.
-
Get a list of targets that match the user context, based on the assigned audiences that include the user.
-
updateAudience(communityId, audienceId, audience)
Update an audience.
-
updateTargets(communityId, target)
Update targets.
Create an audience.
48.0
No
public static ConnectApi.Audience createAudience(String communityId, ConnectApi.AudienceInput audience)
- communityId
Type: String
ID of the Experience Cloud site.
- audience
Type:
ConnectApi.AudienceInputA
ConnectApi.AudienceInputobject that defines the audience.
Type: ConnectApi.Audience
Create targets.
48.0
No
public static ConnectApi.TargetCollection createTargets(String communityId, ConnectApi.TargetCollectionInput target)
- communityId
Type: String
ID of the Experience Cloud site.
- target
Type:
ConnectApi.TargetCollectionInputA
ConnectApi.TargetCollectionInputobject that defines the targets.
Type: ConnectApi.TargetCollection
Delete an audience.
48.0
No
public static Void deleteAudience(String communityId, String audienceId)
- communityId
Type: String
ID of the Experience Cloud site.
- audienceId
Type: String
ID of the audience.
Type: Void
Delete a target.
48.0
No
public static Void deleteTarget(String communityId, String targetId)
- communityId
Type: String
ID of the Experience Cloud site.
- targetId
Type: String
ID of the target.
Type: Void
Get an audience.
48.0
48.0
No
public static ConnectApi.Audience getAudience(String communityId, String audienceId, Boolean includeAudienceCriteria)
- communityId
Type: String
ID of the Experience Cloud site.
- audienceId
Type: String
ID of the audience.
- includeAudienceCriteria
Type: Boolean
Specifies whether to include audience criteria (
true) or not (false). If unspecified, defaults tofalse.
Type: ConnectApi.Audience
Get audience information for a comma-separated list of audience IDs.
48.0
48.0
No
public static ConnectApi.BatchResult[] getAudienceBatch(String communityId, List<String> audienceIds)
- communityId
Type: String
ID of the Experience Cloud site.
- audienceIds
Type: List<String>
Comma-separated list of audience IDs.
Type: ConnectApi.BatchResult[]
The ConnectApi.BatchResult.getResult() method returns a ConnectApi.Audience object and errors for audiences that didn’t load.
Get a list of assigned audiences that match the user context and record information.
51.0
51.0
No
public static ConnectApi.AudienceCollection getAudiences(String communityId, String ipAddress, String domain, String userId, ConnectApi.PublishStatus publishStatus, Boolean includeAudienceCriteria, List<String> targetTypes, String recordId)
communityId
Type: String
ID for an Experience Cloud site, internal, or null.
ipAddress
Type: String
IP address of the user. If null, no audiences with location criteria are returned.
domain
Type: String
Name of the user’s Salesforce custom domain. If null, no audiences with domain criteria are returned.
userId
Type: String
ID of the user. If null, defaults to the ID of the context user.
publishStatus
Type: ConnectApi.PublishStatus
Publish status of the audience. Values are:
DraftLive
If null, defaults to Live.
includeAudienceCriteria
Type: Boolean
Specifies whether to include audience criteria (true) or not (false). If unspecified, defaults to false.
targetTypes
Type: List<String>
Comma-separated list of target types to filter the results. Supported values include:
ExperienceVariation(version 48.0 and later)- Custom object API names, such as
CustomObjectName__c(version 48.0 and later) NavigationLinkSet(version 49.0 and later)Topic(version 49.0 and later)CollaborationGroup(version 49.0 and later)KnowledgeArticle(version 49.0 and later)ContentDocument(version 49.0 and later)ManagedContent(version 49.0 and later)Report(version 49.0 and later)Dashboard(version 49.0 and later)
If null, all target types are returned.
recordId
Type: String
ID of the record for field based criteria. If null, all applicable audiences with field based criteria are returned.
Type: ConnectApi.AudienceCollection
Get a list of assigned audiences that match the user context.
48.0
48.0
No
public static ConnectApi.AudienceCollection getAudiences(String communityId, String ipAddress, String domain, String userId, ConnectApi.PublishStatus publishStatus, Boolean includeAudienceCriteria, List<String> targetTypes)
communityId
Type: String
ID of the Experience Cloud site.
ipAddress
Type: String
IP address of the user. If null, no audiences with location criteria are returned.
domain
Type: String
Name of the user’s Salesforce custom domain. If null, no audiences with domain criteria are returned.
userId
Type: String
ID of the user. If null, defaults to the ID of the context user.
publishStatus
Type: ConnectApi.PublishStatus
Publish status of the audience. Values are:
DraftLive
If null, defaults to Live.
includeAudienceCriteria
Type: Boolean
Specifies whether to include audience criteria (true) or not (false). If unspecified, defaults to false.
targetTypes
Type: List<String>
Comma-separated list of target types to filter the results. Supported values include:
ExperienceVariation(version 48.0 and later)- Custom object API names, such as
CustomObjectName__c(version 48.0 and later) NavigationLinkSet(version 49.0 and later)Topic(version 49.0 and later)CollaborationGroup(version 49.0 and later)KnowledgeArticle(version 49.0 and later)ContentDocument(version 49.0 and later)ManagedContent(version 49.0 and later)Report(version 49.0 and later)Dashboard(version 49.0 and later)
If null, all target types are returned.
Type: ConnectApi.AudienceCollection
Get a target.
48.0
48.0
No
public static ConnectApi.Target getTarget(String communityId, String targetId)
- communityId
Type: String
ID of the Experience Cloud site.
- targetId
Type: String
ID of the target.
Type: ConnectApi.Target
Get target information for a comma-separated list of target IDs.
48.0
48.0
No
public static ConnectApi.BatchResult[] getTargetBatch(String communityId, List<String> targetIds)
- communityId
Type: String
ID for an Experience Cloud site,
internal, ornull.- targetIds
Type: List<String>
Comma-separated list of target IDs.
Type: ConnectApi.BatchResult
The ConnectApi.BatchResult.getResult() method returns a ConnectApi.Target object and errors for targets that didn’t load.
Get a list of targets that match the user context, based on the assigned audiences that include the user.
48.0
48.0
No
public static ConnectApi.TargetCollection getTargets(String communityId, String ipAddress, String domain, String userId, ConnectApi.PublishStatus publishStatus, String recordId, List<String> targetTypes, Boolean includeAudience, Boolean includeAllMatchingTargetsWithinGroup, List<String> groupNames)
communityId
Type: String
ID of the Experience Cloud site.
ipAddress
Type: String
IP address of the user. If null, no audiences with location criteria are returned.
domain
Type: String
Name of the user’s Salesforce custom domain. If null, no audiences with domain criteria are returned.
userId
Type: String
ID of the user. If null, the default is the ID of the context user.
publishStatus
Type: ConnectApi.PublishStatus
Publish status of the target. Values are:
DraftLive
recordId
Type: String
ID of the record, if you want to specify field based criteria in audiences.
targetTypes
Type: List<String>
Comma-separated list of target types to filter the results. Supported values include:
ExperienceVariation(version 48.0 and later)- Custom object API names, such as
CustomObjectName__c(version 48.0 and later) NavigationLinkSet(version 49.0 and later)Topic(version 49.0 and later)CollaborationGroup(version 49.0 and later)KnowledgeArticle(version 49.0 and later)ContentDocument(version 49.0 and later)ManagedContent(version 49.0 and later)Report(version 49.0 and later)Dashboard(version 49.0 and later)
If null, all target types are returned.
includeAudience
Type: Boolean
Specifies whether to include the matching audience (true) or not (false). If null, the default is false.
includeAllMatchingTargetsWithinGroup
Type: Boolean
Specifies whether to include all the matching targets within a target group (true) or not (false). If null, the default is false. If false, the first matching target within each group, based on priority within the group, is returned.
groupNames
Type: List<String>
A comma-separated list of group names. Groups bundle related target and audience pairs.
Type: ConnectApi.TargetCollection
Update an audience.
48.0
No
public static ConnectApi.Audience updateAudience(String communityId, String audienceId, ConnectApi.AudienceInput audience)
- communityId
Type: String
ID of the Experience Cloud site.
- audienceId
Type: String
ID of the audience.
- audience
Type:
ConnectApi.AudienceInputA
ConnectApi.AudienceInputobject that defines the updates to the audience.
Type: ConnectApi.Audience
Update targets.
48.0
No
public static ConnectApi.TargetCollection updateTargets(String communityId, ConnectApi.TargetCollectionUpdateInput target)
- communityId
Type: String
ID of the Experience Cloud site.
- target
Type:
ConnectApi.TargetCollectionUpdateInputA
ConnectApi.TargetCollectionUpdateInputobject that defines the updates for the targets.