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 code below. I'm also aware of two projects, JavaChatterRESTApi and ChatterUtility, however they're not up2date.
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?
Update #1
In the above code, I've used an enterprise connection to create a FeedItem. Using a partner connection, I got the following error:
[[Error fields='{[0]}'
message='Users specified in CreatedById must be active, non-portal users in this organization.'
statusCode='INVALID_CROSS_REFERENCE_KEY'
]
]
which is probably linked to the this Knowledge Article.