1

I am trying to copy feeds from an opportunity to it's related account and I it doesn't seems to be so easy. :)

feed is a complex object as can be seen here so basically I want to copy also the comments and likes.

enter image description here

I have searched all over the network for an answer but I haven't seen something similar. For example, I have gone through those links and many more which helped me to understand a little bit more with what I am facing with,

There is 2 types of feeds which I want to be able to copy: TrackedChange and TextPost.

Regarding TrackedChange , I saw that only the system can generate this kind of feed (mentioned in Chatter_Code_Recipes), is there any way I can mimic and post a similar feed on the account?

Regarding TextPost , I have tried to do the following but I have managed only to copy the main feed without its related objects (comment and likes).

FeedItem opf = [SELECT Id, Type, 
CreatedById, CreatedBy.FirstName, CreatedBy.LastName,
ParentId, Parent.Name, 
Body, Title, 
(SELECT Id, FeedItemId,FieldName, OldValue, NewValue 
        FROM FeedTrackedChanges), 
(SELECT Id, ParentId, CommentBody, CreatedDate,
        CreatedById, CreatedBy.FirstName, CreatedBy.LastName
        FROM FeedComments),
(SELECT CreatedBy.FirstName, CreatedBy.LastName
        FROM FeedLikes)
        FROM FeedItem
WHERE ParentId = '**OPPORTUNITY_ID**' AND ID = '**FEED ID**'];
// system.debug(opf);
// opf.parentId = '**ACCOUNT_ID**';  Doesn't work.. parentId field is          
// not writable
FeedItem opfc = opf.clone(false,true);
opfc.parentId = '**ACCOUNT_ID**'; // Changing the parent Id to account Id
insert opfc; // Insert works but I don't see all the related child objects  (comments, likes, etc.)

Some advises please? Thanks ahead.

6
  • Does it work if you insert the FeedComment and FeedLike objects separately?
    – alouie
    May 22, 2015 at 22:41
  • Yes, I have managed to do it. :) But now ... If I want to copy feeds with type of TrackedChange to the account feed, the only way I find to do so it's by creating feed with TextPost type and edit the body message for it to be something like : 'Field abc has changed from aaa to bbb '. And afterwards this textpost feed will be editable in the account which is not the same like in the opportunity. (TrackedChange are not editable). Need some help here ;)
    – sfdcdev
    May 23, 2015 at 7:32
  • TrackedChanges are system generated only, and so your workaround of creating the TextPost is the best that I can think of too, unfortunately.
    – alouie
    May 23, 2015 at 16:08
  • Ok, thank you very much, Do you know maybe if connectAPI can work here? does it give me additional functionallity? or its just for making Visual force pages and applications. ?
    – sfdcdev
    May 23, 2015 at 16:46
  • The Connect API gives you much more functionality than the sObject API (for example: @-mentions, bookmarks, polls, likes on comments, and much more), but it does not support impersonation like the sObject API does. You can't post a feed item as someone else, and so for your scenario the sObject API is your only viable option. (Also, tracked changes are only system generated -- they can't be created directly by any API.)
    – alouie
    May 23, 2015 at 21:21

0

You must log in to answer this question.

Browse other questions tagged .