Skip to main content
added 26 characters in body
Source Link
slim
  • 107
  • 2
  • 11

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.CreatedByCreatedById = u.Id;
                    update cgf;

Error message: Illegal assignment from Id to NameField is not writeable: CollaborationGroupFeed.CreatedById

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.CreatedBy = u.Id;
                    update cgf;

Error message: Illegal assignment from Id to Name

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

Source Link
slim
  • 107
  • 2
  • 11

How to update reference field in sobject

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.CreatedBy = u.Id;
                    update cgf;

Error message: Illegal assignment from Id to Name