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 take action to 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.
For information about how to use action links, see Working with Action Links.
The following are methods for ActionLinks. All methods are static.
33.0
No
public static ConnectApi.ActionLinkGroupDefinition createActionLinkGroupDefinition(String communityId, ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroup)
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 take action to 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 stand-alone 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.
ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput(); ConnectApi.ActionLinkDefinitionInput actionLinkDefinitionInput = new ConnectApi.ActionLinkDefinitionInput(); ConnectApi.RequestHeaderInput requestHeaderInput1 = new ConnectApi.RequestHeaderInput(); ConnectApi.RequestHeaderInput requestHeaderInput2 = new ConnectApi.RequestHeaderInput(); // Create the action link group definition. actionLinkGroupDefinitionInput.actionLinks = New List<ConnectApi.ActionLinkDefinitionInput>(); actionLinkGroupDefinitionInput.executionsAllowed = ConnectApi.ActionLinkExecutionsAllowed.OncePerUser; actionLinkGroupDefinitionInput.category = ConnectApi.PlatformActionGroupCategory.Primary; // To Do: Verify that the date is in the future. // Action link groups are removed from feed elements on the expiration date. datetime myDate = datetime.newInstance(2016, 3, 1); actionLinkGroupDefinitionInput.expirationDate = myDate; // Create the action link definition. actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Api; actionLinkDefinitionInput.actionUrl = '/services/data/v33.0/chatter/feed-elements'; actionLinkDefinitionInput.headers = new List<ConnectApi.RequestHeaderInput>(); actionLinkDefinitionInput.labelKey = 'Post'; actionLinkDefinitionInput.method = ConnectApi.HttpRequestMethod.HttpPost; actionLinkDefinitionInput.requestBody = '{\"subjectId\": \"me\",\"feedElementType\": \"FeedItem\",\"body\": {\"messageSegments\": [{\"type\": \"Text\",\"text\": \"This is a test post created via an API action link.\"}]}}'; actionLinkDefinitionInput.requiresConfirmation = true; // To Do: Substitute an OAuth value for your Salesforce org. requestHeaderInput1.name = 'Authorization'; requestHeaderInput1.value = 'OAuth 00DD00000007WNP!ARsAQCwoeV0zzAV847FTl4zF.85w.EwsPbUgXR4SAjsp'; actionLinkDefinitionInput.headers.add(requestHeaderInput1); requestHeaderInput2.name = 'Content-Type'; requestHeaderInput2.value = 'application/json'; actionLinkDefinitionInput.headers.add(requestHeaderInput2); // Add the action link definition to the action link group definition. actionLinkGroupDefinitionInput.actionLinks.add(actionLinkDefinitionInput); // Instantiate the action link group definition. ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition = ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput); ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput(); ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput(); ConnectApi.AssociatedActionsCapabilityInput associatedActionsCapabilityInput = new ConnectApi.AssociatedActionsCapabilityInput(); ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput(); ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput(); // Set the properties of the feedItemInput object. feedItemInput.body = messageBodyInput; feedItemInput.capabilities = feedElementCapabilitiesInput; feedItemInput.subjectId = 'me'; // Create the text for the post. messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); textSegmentInput.text = 'Click to post a feed item.'; messageBodyInput.messageSegments.add(textSegmentInput); // The feedElementCapabilitiesInput object holds the capabilities of the feed item. // Define an associated actions capability to hold the action link group. // The action link group ID is returned from the call to create the action link group definition. feedElementCapabilitiesInput.associatedActions = associatedActionsCapabilityInput; associatedActionsCapabilityInput.actionLinkGroupIds = new List<String>(); associatedActionsCapabilityInput.actionLinkGroupIds.add(actionLinkGroupDefinition.id); // Post the feed item. ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
// Get the action link group template Id. ActionLinkGroupTemplate template = [SELECT Id FROM ActionLinkGroupTemplate WHERE DeveloperName='Doc_Example']; // Add binding name-value pairs to a map. // The names are defined in the action link template(s) associated with the action link group template. // Get them from Setup UI or SOQL. Map<String, String> bindingMap = new Map<String, String>(); bindingMap.put('ApiVersion', 'v33.0'); bindingMap.put('Text', 'This post was created by an API action link.'); bindingMap.put('SubjectId', 'me'); // Create ActionLinkTemplateBindingInput objects from the map elements. List<ConnectApi.ActionLinkTemplateBindingInput> bindingInputs = new List<ConnectApi.ActionLinkTemplateBindingInput>(); for (String key : bindingMap.keySet()) { ConnectApi.ActionLinkTemplateBindingInput bindingInput = new ConnectApi.ActionLinkTemplateBindingInput(); bindingInput.key = key; bindingInput.value = bindingMap.get(key); bindingInputs.add(bindingInput); } // Set the template Id and template binding values in the action link group definition. ConnectApi.ActionLinkGroupDefinitionInput actionLinkGroupDefinitionInput = new ConnectApi.ActionLinkGroupDefinitionInput(); actionLinkGroupDefinitionInput.templateId = template.id; actionLinkGroupDefinitionInput.templateBindings = bindingInputs; // Instantiate the action link group definition. ConnectApi.ActionLinkGroupDefinition actionLinkGroupDefinition = ConnectApi.ActionLinks.createActionLinkGroupDefinition(Network.getNetworkId(), actionLinkGroupDefinitionInput); ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput(); ConnectApi.FeedElementCapabilitiesInput feedElementCapabilitiesInput = new ConnectApi.FeedElementCapabilitiesInput(); ConnectApi.AssociatedActionsCapabilityInput associatedActionsCapabilityInput = new ConnectApi.AssociatedActionsCapabilityInput(); ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput(); ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput(); // Define the FeedItemInput object to pass to postFeedElement feedItemInput.body = messageBodyInput; feedItemInput.capabilities = feedElementCapabilitiesInput; feedItemInput.subjectId = 'me'; // The MessageBodyInput object holds the text in the post messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); textSegmentInput.text = 'Click to post a feed item.'; messageBodyInput.messageSegments.add(textSegmentInput); // The FeedElementCapabilitiesInput object holds the capabilities of the feed item. // For this feed item, we define an associated actions capability to hold the action link group. // The action link group ID is returned from the call to create the action link group definition. feedElementCapabilitiesInput.associatedActions = associatedActionsCapabilityInput; associatedActionsCapabilityInput.actionLinkGroupIds = new List<String>(); associatedActionsCapabilityInput.actionLinkGroupIds.add(actionLinkGroupDefinition.id); // Post the feed item. ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), feedItemInput);
33.0
No
public static void deleteActionLinkGroupDefinition(String communityId, String actionLinkGroupId)
Type: Void
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.
33.0
No
public static ConnectApi.PlatformAction getActionLink(String communityId, String actionLinkId)
33.0
No
public static ConnectApi.ActionLinkDiagnosticInfo getActionLinkDiagnosticInfo(String communityId, String actionLinkId)
33.0
No
public static ConnectApi.PlatformActionGroup getActionLinkGroup(String communityId, String actionLinkGroupId)
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.
33.0
No
public static ConnectApi.ActionLinkGroupDefinition getActionLinkGroupDefinition(String communityId, String actionLinkGroupId)
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.