1

I'm trying to update a sobject (CollaborationGroupFeed) via apex, but I am unable to update a particular reference field (in this case: CreatedBy).

Here is my code:

CollaborationGroupFeed cgf = [SELECT Id, CreatedById
                                                 FROM CollaborationGroupFeed
                                                 WHERE Id =: feedElement.Id
                                                 LIMIT 1];

                    User u = [SELECT Id, Name FROM User WHERE FirstName = 'Steve' AND LastName = 'Jobs'];
                    cgf.CreatedById = u.Id;
                    update cgf;

Error message: Field is not writeable: CollaborationGroupFeed.CreatedById

6
  • The actual API Name of the field is CreatedById, not CreatedBy. This field is not writeable.
    – Adrian Larson
    Commented Dec 11, 2015 at 19:10
  • Thanks. I still get an error, but I'll update the question.
    – slim
    Commented Dec 11, 2015 at 19:18
  • Yeah, as I said, this field is not writeable.
    – Adrian Larson
    Commented Dec 11, 2015 at 19:23
  • I think you can open a case to make it writeable, but I am not sure. The real question is, why would you ever want to modify its content?
    – Adrian Larson
    Commented Dec 11, 2015 at 19:23
  • The reason why is I'm writing a trigger to post something in the feed on behalf of someone. Is this not achievable?
    – slim
    Commented Dec 11, 2015 at 19:34

1 Answer 1

4

As Adrian Larson pointed out, the CreatedById field is not writable.

It is a System Field, and from the documentation on System Fields (emphasis mine)

System Fields: The following fields are read-only fields found on most objects. These fields are automatically updated during API operations. For example, the ID field is automatically generated during a create operation and the LastModifiedDate is automatically updated during any operation on an object.

CreatedByIdis automatically set when the record is inserted.

2
  • 3
    and furthermore, even using the new permission Set Audit Fields upon Record Creation at developer.salesforce.com/docs/atlas.en-us.api.meta/api/…, you can't set createdById on CollaborationGropupFeed
    – cropredy
    Commented Dec 11, 2015 at 19:54
  • What DOES this permission do then, I fail to see the point of enabling it under System Permissions? Only for dataloader maybe?
    – rmarq423
    Commented Nov 1, 2019 at 15:10

You must log in to answer this question.

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