ActionLinks Class
Namespace
Usage
An action link is a button on a feed element. Clicking an action link can take a user to a Web page, initiate a file download, or invoke an API call to Salesforce or to an external server. An action link includes a URL and an HTTP method, and can include a request body and header information, such as an OAuth token for authentication. Use action links to integrate Salesforce and third-party services into the feed so that users can drive productivity and accelerate innovation.
There are two views of an action link and an action link group: the definition, and the context user’s view. The definition includes potentially sensitive information, such as authentication information. The context user’s view is filtered by visibility options and the values reflect the state of the context user.
Action link definition can be sensitive to a third party (for example, OAuth bearer token headers). For this reason, only calls made from the Apex namespace that created the action link definition can read, modify, or delete the definition. In addition, the user making the call must have created the definition or have View All Data permission. Use these methods to operate on action link group definitions (which contain action link definitions).
- createActionLinkGroupDefinition(communityId, actionLinkGroup)
- deleteActionLinkGroupDefinition(communityId, actionLinkGroupId)
- getActionLinkGroupDefinition(communityId, actionLinkGroupId)
Use these methods to operate on a context user’s view of an action link or an action link group.
- getActionLink(communityId, actionLinkId)
- getActionLinkGroup(communityId, actionLinkGroupId)
- getActionLinkDiagnosticInfo(communityId, actionLinkId)
For information about how to use action links, see Working with Action Links.
ActionLinks Methods
createActionLinkGroupDefinition(communityId, actionLinkGroup)
API Version
33.0
Requires Chatter
No
Signature
public static ConnectApi.ActionLinkGroupDefinition createActionLinkGroupDefinition(String communityId, ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroup)
Parameters
- communityId
- Type: String
- ID for an Experience Cloud site, internal, or null.
- actionLinkGroup
- Type: ConnectApi.ActionLinkGroupDefinitionInput
- A ConnectApi.ActionLinkGroupDefinitionInput object that defines the action link group.
Return Value
Usage
An action link is a button on a feed element. Clicking an action link can take a user to a Web page, initiate a file download, or invoke an API call to Salesforce or to an external server. An action link includes a URL and an HTTP method, and can include a request body and header information, such as an OAuth token for authentication. Use action links to integrate Salesforce and third-party services into the feed so that users can drive productivity and accelerate innovation.
All action links must belong to a group. Action links in a group are mutually exclusive and share some properties. Define standalone actions in their own action group.
Information in the action link group definition can be sensitive to a third party (for example, OAuth bearer token headers). For this reason, only calls made from the Apex namespace that created the action link group definition can read, modify, or delete the definition. In addition, the user making the call must have created the definition or have View All Data permission.
Example for Defining an Action Link and Posting with a Feed Element
1ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput();
2ConnectApi.ActionLinkDefinitionInput actionLinkDefinitionInput = new ConnectApi.ActionLinkDefinitionInput();
3ConnectApi.RequestHeaderInput requestHeaderInput1 = new ConnectApi.RequestHeaderInput();
4ConnectApi.RequestHeaderInput requestHeaderInput2 = new ConnectApi.RequestHeaderInput();
5
6// Create the action link group definition.
7actionLinkGroupDefinitionInput.actionLinks = New List<ConnectApi.ActionLinkDefinitionInput>();
8actionLinkGroupDefinitionInput.executionsAllowed = ConnectApi.ActionLinkExecutionsAllowed.OncePerUser;
9actionLinkGroupDefinitionInput.category = ConnectApi.PlatformActionGroupCategory.Primary;
10// To Do: Verify that the date is in the future.
11// Action link groups are removed from feed elements on the expiration date.
12datetime myDate = datetime.newInstance(2016, 3, 1);
13actionLinkGroupDefinitionInput.expirationDate = myDate;
14
15// Create the action link definition.
16actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Api;
17actionLinkDefinitionInput.actionUrl = '/services/data/v33.0/chatter/feed-elements';
18actionLinkDefinitionInput.headers = new List<ConnectApi.RequestHeaderInput>();
19actionLinkDefinitionInput.labelKey = 'Post';
20actionLinkDefinitionInput.method = ConnectApi.HttpRequestMethod.HttpPost;
21actionLinkDefinitionInput.requestBody = '{\"subjectId\": \"me\",\"feedElementType\": \"FeedItem\",\"body\": {\"messageSegments\": [{\"type\": \"Text\",\"text\": \"This is a test post created via an API action link.\"}]}}';
22actionLinkDefinitionInput.requiresConfirmation = true;
23
24// To Do: Substitute an OAuth value for your Salesforce org.
25requestHeaderInput1.name = 'Authorization';
26requestHeaderInput1.value = 'OAuth 00DD00000007WNP!ARsAQCwoeV0zzAV847FTl4zF.85w.EwsPbUgXR4SAjsp';
27actionLinkDefinitionInput.headers.add(requestHeaderInput1);
28
29requestHeaderInput2.name = 'Content-Type';
30requestHeaderInput2.value = 'application/json';
31actionLinkDefinitionInput.headers.add(requestHeaderInput2);
32
33// Add the action link definition to the action link group definition.
34actionLinkGroupDefinitionInput.actionLinks.add(actionLinkDefinitionInput);
35
36// Instantiate the action link group definition.
37ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition = ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput);
38
39ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
40ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput();
41ConnectApi.AssociatedActionsCapabilityInput associatedActionsCapabilityInput = new ConnectApi.AssociatedActionsCapabilityInput();
42ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
43ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
44
45// Set the properties of the feedItemInput object.
46feedItemInput.body = messageBodyInput;
47feedItemInput.capabilities = feedElementCapabilitiesInput;
48feedItemInput.subjectId = 'me';
49
50// Create the text for the post.
51messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
52textSegmentInput.text = 'Click to post a feed item.';
53messageBodyInput.messageSegments.add(textSegmentInput);
54
55
56// The feedElementCapabilitiesInput object holds the capabilities of the feed item.
57// Define an associated actions capability to hold the action link group.
58// The action link group ID is returned from the call to create the action link group definition.
59feedElementCapabilitiesInput.associatedActions = associatedActionsCapabilityInput;
60associatedActionsCapabilityInput.actionLinkGroupIds = new List<String>();
61associatedActionsCapabilityInput.actionLinkGroupIds.add(actionLinkGroupDefinition.id);
62
63// Post the feed item.
64ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);Example for Defining an Action Link in a Template and Posting with a Feed Element
1// Get the action link group template Id.
2ActionLinkGroupTemplate template = [SELECT Id FROM ActionLinkGroupTemplate WHERE DeveloperName='Doc_Example'];
3
4// Add binding name-value pairs to a map.
5// The names are defined in the action link template(s) associated with the action link group template.
6// Get them from Setup UI or SOQL.
7Map<String, String> bindingMap = new Map<String, String>();
8bindingMap.put('ApiVersion', 'v33.0');
9bindingMap.put('Text', 'This post was created by an API action link.');
10bindingMap.put('SubjectId', 'me');
11
12// Create ActionLinkTemplateBindingInput objects from the map elements.
13List<ConnectApi.ActionLinkTemplateBindingInput> bindingInputs = new List<ConnectApi.ActionLinkTemplateBindingInput>();
14
15for (String key : bindingMap.keySet()) {
16 ConnectApi.ActionLinkTemplateBindingInput bindingInput = new ConnectApi.ActionLinkTemplateBindingInput();
17 bindingInput.key = key;
18 bindingInput.value = bindingMap.get(key);
19 bindingInputs.add(bindingInput);
20}
21
22// Set the template Id and template binding values in the action link group definition.
23ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput();
24actionLinkGroupDefinitionInput.templateId = template.id;
25actionLinkGroupDefinitionInput.templateBindings = bindingInputs;
26
27// Instantiate the action link group definition.
28ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition =
29 ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput);
30
31ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
32ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput();
33ConnectApi.AssociatedActionsCapabilityInput associatedActionsCapabilityInput = new ConnectApi.AssociatedActionsCapabilityInput();
34ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
35ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
36
37// Define the FeedItemInput object to pass to postFeedElement
38feedItemInput.body = messageBodyInput;
39feedItemInput.capabilities = feedElementCapabilitiesInput;
40feedItemInput.subjectId = 'me';
41
42// The MessageBodyInput object holds the text in the post
43messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
44
45textSegmentInput.text = 'Click to post a feed item.';
46messageBodyInput.messageSegments.add(textSegmentInput);
47
48
49// The FeedElementCapabilitiesInput object holds the capabilities of the feed item.
50// For this feed item, we define an associated actions capability to hold the action link group.
51// The action link group ID is returned from the call to create the action link group definition.
52feedElementCapabilitiesInput.associatedActions = associatedActionsCapabilityInput;
53associatedActionsCapabilityInput.actionLinkGroupIds = new List<String>();
54associatedActionsCapabilityInput.actionLinkGroupIds.add(actionLinkGroupDefinition.id);
55
56// Post the feed item.
57ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);deleteActionLinkGroupDefinition(communityId, actionLinkGroupId)
API Version
33.0
Requires Chatter
No
Signature
public static void deleteActionLinkGroupDefinition(String communityId, String actionLinkGroupId)
Parameters
Return Value
Type: Void
Usage
Information in the action link group definition can be sensitive to a third party (for example, OAuth bearer token headers). For this reason, only calls made from the Apex namespace that created the action link group definition can read, modify, or delete the definition. In addition, the user making the call must have created the definition or have View All Data permission.
getActionLink(communityId, actionLinkId)
API Version
33.0
Requires Chatter
No
Signature
public static ConnectApi.PlatformAction getActionLink(String communityId, String actionLinkId)
Parameters
Return Value
getActionLinkDiagnosticInfo(communityId, actionLinkId)
API Version
33.0
Requires Chatter
No
Signature
public static ConnectApi.ActionLinkDiagnosticInfo getActionLinkDiagnosticInfo(String communityId, String actionLinkId)
Parameters
Return Value
getActionLinkGroup(communityId, actionLinkGroupId)
API Version
33.0
Requires Chatter
No
Signature
public static ConnectApi.PlatformActionGroup getActionLinkGroup(String communityId, String actionLinkGroupId)
Parameters
Return Value
Usage
All action links must belong to a group. Action links in a group are mutually exclusive and share some properties. Action link groups are accessible by clients, unlike action link group definitions.
getActionLinkGroupDefinition(communityId, actionLinkGroupId)
API Version
33.0
Requires Chatter
No
Signature
public static ConnectApi.ActionLinkGroupDefinition getActionLinkGroupDefinition(String communityId, String actionLinkGroupId)
Parameters
Return Value
Usage
Information in the action link group definition can be sensitive to a third party (for example, OAuth bearer token headers). For this reason, only calls made from the Apex namespace that created the action link group definition can read, modify, or delete the definition. In addition, the user making the call must have created the definition or have View All Data permission.