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