• Maximilian-Albin Ekström
  • 0 Points
  • Member since 2020

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
We have a piece of code which is working fine for Salesforce licenses but is failing when it runs under Site Guest User licence in client's instance as a part of managed package. This code is in Attachment object 'on insert' trigger.
FeedItem resumeFile = new FeedItem(
	ParentId = resumePoolChatterGroup.Id,
	Type = 'ContentPost',
	ContentData = resumeAttachment.Body,
	ContentFileName = resumeAttachment.Name,
	CreatedById = idToContactMap.get(resumeAttachment.ParentId).OwnerId
It failed on line:
CreatedById = idToContactMap.get(resumeAttachment.ParentId).OwnerId
and tells:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AVTRRT.Trigger_Attachment: execution of AfterInsert caused by: line 7, column 37: Dependent class is invalid and needs recompilation: AVTRRT.ChatterResume: line 70, column 66: Field is not writeable: FeedItem.CreatedById: []
In Salesforce documentation it tells:
If the logged-in user has the “Insert System Field Values for Chatter Feeds” user permission, the create field property is available on CreatedBy and CreatedDate system fields for this object. This allows the logged-in user to set these fields to the original post author and creation date upon migration instead of accepting the system field value when migrated, which would be the logged-in user and the date the migration was performed, respectively. The fields can't be updated after migration.
I tried to set “Insert System Field Values for Chatter Feeds” permission but didn't find such option.

Also, the issue is happening only for one of client's Force.com Site. For another one we don't have such issue.

Is it possible to make it work?