• Mikhail Ivanov
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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? 

I tried to look into debug logs but I didn't get any of debug logs records for those VF pages. But for other VF page I can get debug logs.

Also if I clean cookies in browser then for a short run I can open those problem VF pages without errors. But after I get the error once again.

How to fix the error without cleaning cookies.
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? 

I tried to look into debug logs but I didn't get any of debug logs records for those VF pages. But for other VF page I can get debug logs.

Also if I clean cookies in browser then for a short run I can open those problem VF pages without errors. But after I get the error once again.

How to fix the error without cleaning cookies.