2

When trying to create a FeedItem through the ApexRest I'm always getting the following error:

[{"errorCode":"APEX_ERROR","message":"System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]\n\nClass.WS_SALES_V1_Document.post: line 61, column 1"}]

But according to the Salesforce docs, the Body field is Optional when Type is ContentPost.
Apex code of FeedItem creation(the insert fi; is line 61 by the way):

FeedItem fi = new FeedItem();
fi.ParentId = o.Id;
fi.Type = 'ContentPost';
fi.Visibility = 'AllUsers';
insert fi;

Is it a bug? Is documentation not up-to-date?

EDIT

I'm using API version 36.0

3
  • 2
    As per the same doc If you set Type to ContentPost, also specify ContentData and ContentFileName. so give these two and then try. Apr 29 '16 at 8:30
  • @TusharSharma thanks for the comment, but according to that same doc, both ContentData and ContentFileName are Available in API version 35.0 and earlier only.
    – Novarg
    Apr 29 '16 at 8:48
  • @Novarg .. I think Tushar is right about it. Here is the latest documentation URL, the url you pointed is of 2016. developer.salesforce.com/docs/atlas.en-us.object_reference.meta/… here it say those two Tushar mentioned are required fields
    – Raj
    Feb 28 '20 at 4:27
-1

The error says you have to include the Body field. fi.Body = 'body text';

1
  • For type content, body is not required but attachments are.
    – Raj
    Feb 28 '20 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.