You need to sign in to do that
Don't have an account?
Enry
Created by user in chatter api connect
Hi. I'm using the chatter connect to create a chatter post.
Ref: Connect
All works fine but i want to specify the user that creates the chatter post.
In the previous version of my code, i don't use the connect and i have the following instruction:
testpost.CreatedById=user.id;
Do you know how i can do this in the connect api chatter?
My class:
Global class HappyBirthdayRandomPilot implements Schedulable{ //FOR TEST METHOD public static String CRON_EXP = '0 0 0 3 9 ? 2022'; Global void execute(SchedulableContext sc) { // SEARCH BY STATIC RESOURCE NAME List<StaticResource> Pictures=[Select Name, ContentType, Body From StaticResource where Name like 'PicturehappyBirthday%']; // IS THE USER BIRTHDAY? List<user> lstu=[SELECT id,name,date_of_birth__c FROM user WHERE CALENDAR_MONTH(date_of_birth__c)=:date.today().month() AND DAY_IN_MONTH(date_of_birth__c)=:date.today().day()]; CollaborationGroup group=[Select id,name from CollaborationGroup where Name like 'name%' limit 1]; //String communityId = null; for(User u:lstu) { //GENERATE A RANDOM NUMBER [0-5] TO SELECT THE PICTURE Integer choice=math.mod(Integer.valueof(Math.random()*100),6); Blob Decodedbody=Pictures[choice].body; // CREATE A FEED_ITEM_TEXT ConnectApi.MessageBodyInput messageInput = new ConnectApi.MessageBodyInput(); messageInput.messageSegments = new List<ConnectApi.MessageSegmentInput>(); ConnectApi.TextSegmentInput textSegment = new ConnectApi.TextSegmentInput(); textSegment.text = 'Happy birthday to '; messageInput.messageSegments.add(textSegment); ConnectApi.MentionSegmentInput mentionSegment = new ConnectApi.MentionSegmentInput(); mentionSegment.id = u.id; messageInput.messageSegments.add(mentionSegment); textSegment = new ConnectApi.TextSegmentInput(); textSegment.text = '!'; messageInput.messageSegments.add(textSegment); ConnectApi.FeedItemInput input = new ConnectApi.FeedItemInput(); input.body = messageInput; // POST FILE_FEED_ITEM ConnectApi.NewFileAttachmentInput fileIn = new ConnectApi.NewFileAttachmentInput(); fileIn.title ='Wishes!'; fileIn.description = ''; Input.attachment = fileIn; string contentType='image/jpeg'; ConnectApi.BinaryInput feedBinary = new ConnectApi.BinaryInput(Decodedbody,contentType, 'Wishes!.jpg'); // PARAMETERS(communityId, feedType, subjectId, input,filebody); ConnectApi.ChatterFeeds.postFeedItem(null,ConnectApi.FeedType.Record,group.id,Input, feedBinary); } } }
Thanks in advantage for any advice.
BR.
This is documented in "Differences Between ConnectApi Classes and Other Apex Classes":
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_connectapi_differences.htm
All Answers
This is documented in "Differences Between ConnectApi Classes and Other Apex Classes":
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_connectapi_differences.htm
I want to get the id and nickname of the user who created the feeditem / comment using ConnectApi.
Could you please help me with this?
Thanks.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_getFeedItemsFromFeed_2 (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_ConnectAPI_ChatterFeeds_static_methods.htm#apex_ConnectAPI_ChatterFeeds_getFeedItemsFromFeed_2" target="_blank)