We executed a migration from another system into a Salesforce customer community recently, but were unable to migrate forum posts as chatter questions and answers because the system is not allowing us to set the CreatedById on FeedItems and FeedComments to the id of an active communities user. As I understand, having the "Insert System Field Values for Chatter Feeds" should allow us to update this field on insert (in addition to CreatedDate). From https://developer.salesforce.com/page/Chatter_Code_Recipes (and other documentation sources, as well as past experience, corroborate this):

"For Chatter integration/migration use cases, the logged-in user should have the 'Insert System Field Values for Chatter Feeds' user permission enabled for their profile. That allows you to manually set the CreatedById and CreatedDate system fields for the FeedItem, FeedComment and FeedLike objects to match the original post author and creation date/time."

The error I am receiving when attempting to set the CreatedById says "Users specified in CreatedById must be active users in this organization." All of the community users referenced in the import calls were active. I can reproduce this simply by running this script via anonymous APEX (while authorized as a user with the "Insert System Field Values for Chatter Feeds" permission):

FeedItem item = new FeedItem(
    Title = 'Test',
    Body = 'Test',
    Type = 'QuestionPost',
    ParentId = '{id of a parent record}',
    NetworkScope = '{id of the community}',
    CreatedById = '{id of an active user in the community}'
insert item;

This returns the error

"System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Users specified in CreatedById must be active users in this organization.: []."

The user is definitely active, and it works when I try to post as a non-community user.

I've tried this using the id of the user, contact, and other records that the communities user should have at least read permission to. I've also tried this with a custom object record explicitly owned by the communities member. Does the user need write permission on the parent to post a chatter record to it? I've also tried various settings for "NetworkScope" with no luck.

We don't really care what the parent of the FeedItem is in our implementation - we are managing feeds using TopicAssignments to represent various forums.

Any help in understanding why this is happening and how we can fix or work around it would be greatly appreciated. Users are now active in our system but have no access to historical forums data.

Thank you,

Daniel Woodall

  • I know you said you dont care, but what are you using as a parent for the posts?
    – CyberJus
    Apr 7, 2015 at 23:24
  • Thanks for responding CyberJus. I've tried using the User record of the communities user, the related Contact record, and a custom object record owned by the communities user I am trying to post as. In all cases I've used the proper NetworkScope for the parentId object type. Apr 8, 2015 at 23:57

3 Answers 3


I have tried this in the past and even though there is specific permission to set the CreatedById on inserted Chatter posts, it does not work to create FeedItems via Apex where the CreatedById is a Communities user. There is a knowledge article here https://help.salesforce.com/apex/HTViewSolution?id=000188047&language=en_US that mentions it does not work with Portal User accounts, but I have found that true for community users as well.

Here is an Idea from the IdeaExchange https://success.salesforce.com/ideaView?id=08730000000l3X4AAI

  • Thanks for following up and for the useful links. I'd come across the knowledge article before but was hoping that communities users would be different since chatter is such a core communities feature. I hadn't found the IdeaExchange post (and frankly was hoping not to since that pretty much cements it as a gap in Salesforce functionality). I've upvoted it but I fear this may be another one for the idea graveyard. I'm going to wait a day or two in case any clever workarounds pop up - otherwise I'll mark this as best answer for the IdeaExchange link. Apr 9, 2015 at 7:17
  • You may also want to post in the Communities product group of the success community. This issue has come up before, so I am pretty sure the product managers are aware of it. It doesn't hurt to give them more feedback.
    – CyberJus
    Apr 9, 2015 at 12:39

Try setting the NetworkScope to 'AllNetworks' and see if that works for you.

Based on this documentation: https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_feeditem.htm If you search on NetworkScope, you need to set the network scope to AllNetworks unless you are posting under a User or a Group.

  • Thanks for the response AK10. I have tried a couple of different objects as the parentId. When I set it as a user, I used the communityId for NetworkScope. When I set it as a custom object owned by the community user, I used "AllNetworks". In any case where I used the wrong NetworkId, the resulting Salesforce error was pretty clear about what I needed to do. When using the correct NetworkId, I get the "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Users specified in CreatedById must be active users in this organization.: []." error. Apr 8, 2015 at 23:54

Salesforce support all the way.

Otherwise.. here is your only tedious solution it sounds like:

  1. Licenses cannot be changed away from portal/comm users.. which sucks because it would be nice to switch the license temporarily to perform the changes.
  2. So, create a process by which someone logs in as EACH community user. As the running user you have a VF page that can run the import of "current user" records without specifying the createdbyid. They should show up properly. (If you are using Topics, you might need to assign special "topic" permissions via a permission set, by experience here)
    • The person that logs in would be an admin, easily from the community contact page. Hire interns or pre order a case of red-bull and schedule a massage.
    • Just thought of another idea: You could setup the page above, then use a browser script to Log in as comm user, click a button to import, then log out and keep doing this. Pre-store the data into a custom object with custom lookup field pointing to the community user. Set some flags in that object so that you don't get duplicates.

Also you could develop a notification for the community users so when they log in they get the prompt "There are forum posts that you have created in the past etc.. would you like to migrate them into Salesforce now?".

  • Thanks for the detailed suggestion Mike. We had considered a similar process, but I don't think there is a way we can set the CreatedDates appropriately with this approach (since portal users cannot have the "Insert System Field Values for Chatter Feeds" permission). If we can't find a way to set both the CreatedById and the CreatedDate correctly, this may be our best option as having the post show the correct posting user is more important than showing the correct posting time, and we can always inject the old timestamp into the message. Apr 9, 2015 at 7:08
  • You got it, best of luck. Apr 10, 2015 at 3:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .