Newer Version Available

This content describes an older version of this product. View Latest

Recommendations Class

Access information about recommendations and reject recommendations.

Namespace

ConnectApi

Recommendations Methods

The following are methods for Recommendations. All methods are static.

getRecommendationForUser(communityId, userId, action, objectId)

Returns the recommendation for the context user for the specified action and object ID.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.RecommendationCollection getRecommendationForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, String objectId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
objectId
Type: String
Specifies the object to take action on.
  • If action is follow, objectId is a user ID, file ID, or record ID.
  • If action is join, objectId is a group ID.
  • If action is view, objectId is a user ID, file ID, group ID, record ID, or custom recommendation ID (version 34.0 and later).

getRecommendationsForUser(communityId, userId, contextAction, contextObjectId, maxResults)

Returns the user, group, file, record, and custom recommendations for the context user.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.RecommendationCollection getRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.

Usage

If you want to get recommendations based on a recent action performed, such as following a user, use contextAction and contextObjectId together. For example, if you just followed Pam, you specify follow for contextAction and Pam’s user ID for contextObjectId.

This method only recommends users who are followed by people who follow Pam. In this example, John follows Pam so the method returns a recommendation for you to follow Suzanne since John also follows Suzanne.Your new recommendation to follow Suzanne.

getRecommendationsForUser(communityId, userId, action, contextAction, contextObjectId, maxResults)

Returns the recommendations for the context user for the specified action.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.RecommendationCollection getRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.

Usage

If you want to get recommendations based on a recent action performed, such as following a user, use contextAction and contextObjectId together. For example, if you just followed Pam, you specify follow for contextAction and Pam’s user ID for contextObjectId.

This method only recommends users who are followed by people who follow Pam. In this example, John follows Pam so the method returns a recommendation for you to follow Suzanne since John also follows Suzanne.Your new recommendation to follow Suzanne.

getRecommendationsForUser(communityId, userId, action, objectCategory, contextAction, contextObjectId, maxResults)

Returns the recommendations for the context user for the specified action and object category.

API Version

33.0

Requires Chatter

Yes

Signature

public static ConnectApi.RecommendationCollection getRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, String objectCategory, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
objectCategory
Type: String
  • If action is follow, objectCategory is users, files, or records.
  • If action is join, objectCategory is groups.
  • If action is view, objectCategory is users, files, groups, records, or custom.
You can also specify a key prefix, the first three characters of the object ID, as the objectCategory. Valid values are:
  • If action is follow, objectCategory is 005 (users), 069 (files), or 001 (accounts), for example.
  • If action is join, objectCategory is 0F9 (groups).
  • If action is view, objectCategory is 005 (users), 069 (files), 0F9 (groups), 0RD (custom recommendations), or 001 (accounts), for example.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.

Usage

If you want to get recommendations based on a recent action performed, such as following a user, use contextAction and contextObjectId together. For example, if you just followed Pam, you specify follow for contextAction and Pam’s user ID for contextObjectId.

This method only recommends users who are followed by people who follow Pam. In this example, John follows Pam so the method returns a recommendation for you to follow Suzanne since John also follows Suzanne.Your new recommendation to follow Suzanne.

rejectRecommendationForUser(communityId, userId, action, objectId)

Rejects the recommendation for the context user for the specified action and object ID.

API Version

33.0

Requires Chatter

Yes

Signature

public static rejectRecommendationForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, String objectId)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation. Supported values are:
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
objectId
Type: String
Specifies the object to take action on.
  • If action is follow, objectId is a user ID, file ID, or record ID.
  • If action is join, objectId is a group ID.
  • If action is view, objectId is a custom recommendation ID.

Return Value

Type: Void

rejectRecommendationForUser(communityId, userId, action, objectEnum)

Rejects the static recommendation for the context user.

API Version

34.0

Requires Chatter

Yes

Signature

public static rejectRecommendationForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, ConnectApi.RecommendedObjectType objectEnum)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation. Supported values are:
  • view—View a static recommendation.
objectEnum
Type: ConnectApi.​RecommendedObjectType
Specifies the object type to take action on.
  • Today—Static recommendations that don’t have an ID, for example, the Today app recommendation.

Return Value

Type: Void

Recommendations Test Methods

The following are the test methods for Recommendations. All methods are static.

For information about using these methods to test your ConnectApi code, see Testing ConnectApi Code.

setTestGetRecommendationForUser(communityId, userId, action, objectId, result)

Registers a ConnectApi.RecommendationCollection object to be returned when getRecommendationForUser is called with matching parameters in a test context. You must use the method with the same parameters or the code throws an exception.

API Version

33.0

Requires Chatter

Yes

Signature

public static Void setTestGetRecommendationForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, String objectId, ConnectApi.RecommendationCollection result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
objectId
Type: String
Specifies the object to take action on.
  • If action is follow, objectId is a user ID, file ID, or record ID.
  • If action is join, objectId is a group ID.
  • If action is view, objectId is a user ID, file ID, group ID, record ID, or custom recommendation ID.
result
Type: ConnectApi.RecommendationCollection
The object containing test data.

Return Value

Type: Void

setTestGetRecommendationsForUser(communityId, userId, contextAction, contextObjectId, maxResults, result)

Registers a ConnectApi.RecommendationCollection object to be returned when getRecommendationsForUser is called with matching parameters in a test context. Use the method with the same parameters or the code throws an exception.

API Version

33.0

Requires Chatter

Yes

Signature

public static Void setTestGetRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults, ConnectApi.RecommendationCollection result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.
result
Type: ConnectApi.RecommendationCollection
The object containing test data.

Return Value

Type: Void

setTestGetRecommendationsForUser(communityId, userId, action, contextAction, contextObjectId, maxResults, result)

Registers a ConnectApi.RecommendationCollection object to be returned when getRecommendationsForUser is called with matching parameters in a test context. Use the method with the same parameters or the code throws an exception.

API Version

33.0

Requires Chatter

Yes

Signature

public static Void setTestGetRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults, ConnectApi.RecommendationCollection result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.
result
Type: ConnectApi.RecommendationCollection
The object containing test data.

Return Value

Type: Void

setTestGetRecommendationsForUser(communityId, userId, action, objectCategory, contextAction, contextObjectId, maxResults, result)

Registers a ConnectApi.RecommendationCollection object to be returned when getRecommendationsForUser is called with matching parameters in a test context. Use the method with the same parameters or the code throws an exception.

API Version

33.0

Requires Chatter

Yes

Signature

public static Void setTestGetRecommendationsForUser(String communityId, String userId, ConnectApi.RecommendationActionType action, String objectCategory, ConnectApi.RecommendationActionType contextAction, String contextObjectId, Integer maxResults, ConnectApi.RecommendationCollection result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
userId
Type: String
The ID for the context user or the keyword me.
action
Type: ConnectApi.​RecommendationActionType
Specifies the action to take on a recommendation.
  • follow—Follow a file, record, or user.
  • join—Join a group.
  • view—View a file, group, record, user, or custom recommendation.
objectCategory
Type: String
  • If action is follow, objectCategory is users, files, or records.
  • If action is join, objectCategory is groups.
  • If action is view, objectCategory is users, files, groups, records, or custom.
You can also specify a key prefix, the first three characters of the object ID, as the objectCategory. Valid values are:
  • If action is follow, objectCategory is 005 (users), 069 (files), or 001 (accounts), for example.
  • If action is join, objectCategory is 0F9 (groups).
  • If action is view, objectCategory is 005 (users), 069 (files), 0F9 (groups), 0RD (custom recommendations), or 001 (accounts), for example.
contextAction
Type: ConnectApi.​RecommendationActionType
Action that the context user just performed. Supported values are:
  • follow
  • view
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
contextObjectId
Type: String
ID of the object that the context user just perfomed an action on.
  • If contextAction is follow, contextObjectId is a user ID, file ID, or record ID.
  • If contextAction is view, contextObjectId is a user ID, file ID, group ID, or record ID.
Use contextAction and contextObjectId together to get new recommendations based on the action just performed. If you don’t want recommendations based on a recent action, specify null.
maxResults
Type: Integer
Maximum number of recommendation results; default is 10. Value must be greater than 0.
result
Type: ConnectApi.RecommendationCollection
The object containing test data.

Return Value

Type: Void