I Was of view, through rest API , only single record can be created in SFDC
but this link has left me intrigued
Create Multiple records Via Rest
Through CURL using above tree resource, I'm able to create multiple records via Rest, at once .
But I've question, how can I use this tree resource in JAVA Program to create records? Is this possible ?
I was trying something like this :
JSONParser parser = new JSONParser();
// Parser parsing JSON File having multiple records
Object obj = parser.parse(new FileReader("C:/Users/ABCuser/Documents/CURL/NewAccount.JSON"));
httpclient = new HttpClient();
PostMethod mypost = new PostMethod(uri);
String jsonText = obj.toString();
System.out.println("\n_JSON TEXT=" + jsonText);
mypost.setRequestHeader("Authorization", "OAuth " + accessToken);
mypost.setRequestEntity(new StringRequestEntity(jsonText, "application/json", "UTF-8"));
int response=httpclient.executeMethod(mypost);
At last , it just throws error with error code 404:
[{"errorCode":"NOT_FOUND","message":"The requested resource does not
exist"}]
my question : My reason is, if this works in CURL, then it should be working in JAVA also, but I don't know, how I should proceed.
Best Answer
This is possible in java. I tried your code and it is working. As per my observation only thing which could be culprit here is the uri. Below is the code snippet where I have mentioned uri directly.
Below is the output:
Let me know if you face any issue here.