Skip to main content
1 of 3

How to create a FeedItem with SOAP API?

I'm trying to fetch certain FeedItems and then save them. None of these two things I could achieve using Java and SOAP, but here I'll focus on only one, and that is saving.

SOAP API version is 32.0, it's an enterpise WSDL, and I'm using the following code:

String userID = "user id";
FeedItem newFeed = new FeedItem();

// newFeed.setId(feed.getId());
newFeed.setBody("I don't wanna say hello world, because noone sees me.");
newFeed.setParentId(userID);
newFeed.setCreatedById(userID);
com.sforce.soap.enterprise.sobject.SObject[] objects = { newFeed };
SaveResult res = eConn().create(objects)[0];
System.out.println(Arrays.toString(res.getErrors()));

and it gives me this error:

[[Error  fields='{[0]}'
 message='invalid cross reference id'
 statusCode='INVALID_CROSS_REFERENCE_KEY'
]
]

However, when working in Apex, the following, analogue, code works:

String userID = 'user id';
FeedItem newFeed = new FeedItem();

// newFeed.Id = feed.getId = ;
newFeed.Body = 'I dont wanna say hello world, because noone sees me.';
newFeed.ParentId = userID;
newFeed.CreatedById = userID;
insert newFeed;

Question is: Why doesn't the Java code work?