function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CypherCypher 

Custom Object Chatter Feed

I am new to Apex, so my coding is terrible - I am looking for some help.  According to the Chatter code recipes, I can add a feeditem like this:

//Adding a Text post
02FeedItem post = new FeedItem();
03post.ParentId = oId; //eg. Opportunity id, custom object id..
04post.Body = 'Enter post text here';
05

insert post;

but, it does NOT appear to work on a custom object's feed  For example

 

List<Aircraft_Engine__c> Engine = New List<Aircraft_Engine__c>();
Engine = [SELECT Id from Aircraft_Engine__c where Name =: sHashtag limit 1];

Aircraft_Engine__Feed EngineFeed = new Aircraft_Engine__Feed();

EngineFeed.ParentId = 'TEST'; //HERE IS THE ERROR
EngineFeed.Body = sText;
insert EngineFeed;

 

 

the code won;t compile at the line above and has the error: "Save Error: Field is not writeable: Aircraft_Engine__Feed.ParentId

 

Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
CypherCypher

I solved it myself:  You just use the FeedItem object and it places the chatter in the correct place using the parentid!