You need to sign in to do that
Don't have an account?
Amit Loh
connected API sample to post to URL via code
I see
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_define_post_action_link.htm
Above link code works for me to post to API.
http://salesforce.stackexchange.com/questions/69472/ui-actionlink-to-salesforce1-custom-visualforce-page
but this only posts to API and second link does not have complete sample.
I need a sample code that opens up another apex page.
I tried but it gives error
// Create the action link definition.
actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Api; (I need this to be Ui)
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;
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_define_post_action_link.htm
Above link code works for me to post to API.
http://salesforce.stackexchange.com/questions/69472/ui-actionlink-to-salesforce1-custom-visualforce-page
but this only posts to API and second link does not have complete sample.
I need a sample code that opens up another apex page.
I tried but it gives error
// Create the action link definition.
actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Api; (I need this to be Ui)
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;
I'd rather help you through this than provide a full code sample.
All Answers
This post works but I need a click on this post to open a new apex URL and not API post.
- Change the actionType to ConnectApi.ActionLlinkType.Ui
- Change the actionUrl to the URL of your VisualForce page (or whatever webpage you want to use)
- Change the method to ConnectApi.HttpRequestMethod.HttpGet
- Remove the requestBody, since that's only for API-type action links
So it would be something like this:// Create the action link definition.
actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Ui;
actionLinkDefinitionInput.actionUrl = 'https://my.website.com';
actionLinkDefinitionInput.headers = new List<ConnectApi.RequestHeaderInput>();
actionLinkDefinitionInput.labelKey = 'Post';
actionLinkDefinitionInput.method = ConnectApi.HttpRequestMethod.HttpGet;
actionLinkDefinitionInput.requiresConfirmation = true;
// Create the action link definition.
actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Ui;
actionLinkDefinitionInput.actionUrl = 'https://my.website.com';
actionLinkDefinitionInput.labelKey = 'Post';
actionLinkDefinitionInput.method = ConnectApi.HttpRequestMethod.HttpGet;
actionLinkDefinitionInput.requiresConfirmation = true;
caused by: System.NullPointerException: Attempt to de-reference a null object
Can someone give me working simple full sample with
actionLinkDefinitionInput.actionType = ConnectApi.ActionLinkType.Ui;
sample working post code-
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; this I need .Ui
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 item12345.';
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, null);
ConnectApi.FeedElement feedElement1 = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), 'me', ConnectApi.FeedElementType.FeedItem, 'I am on vacation this week.</br>Please approve tender Urgently');
I'd rather help you through this than provide a full code sample.
How to post to a salesforce group?
Right now I am posting with me keyword. I want to post to a public group created.
ConnectApi.FeedElement feedElement1 = ConnectApi.ChatterFeeds.postFeedElement(Network.getNetworkId(), 'me', ConnectApi.FeedElementType.FeedItem, 'I am on vacation this week.</br>Please approve tender Urgently');
I tried
String SOQL = 'SELECT Id,name FROM Group WHERE Type = \'PRApprovers\'';
group1 = Database.Query(SOQL);
Group group2=group1.get(0); but its giving me error
This is confusing, but the groups in Chatter use the CollaborationGroup sObject, not the Group sObject. So you'll want to do something like this if you want to make a SOQL query:
List<CollaborationGroup> g = [SELECT Id, Name FROM CollaborationGroup WHERE ...];
See the CollaborationGroup sObject documentation for more info:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_collaborationgroup.htm
As an alternative, you could make the post somewhere in Chatter and @mention everyone in the group as part of your message. Or you make individual Chatter posts to each user's profile (by setting the subjectId to the user ID when you call postFeedElement -- there's also a method called postFeedElementBatch that lets you make multiple posts in a single call).
string MGGroupId = [SELECT Name FROM CollaborationGroup where Name = 'TenderApprovers'].Id;
System.debug(MGGroupId);
Now how can I add 6 to 7 lines of text with parameters in this chatter post(I was able to add 2 buttons approve/reject) coming from querystring like below
TenderID=querystringval1
Tendername=querystringval2
TenderDate=querystringparam3 etc..