You need to sign in to do that
Don't have an account?
Suganya Subrayan
How to insert the data to salesforce?
Hi,
How to insert the data to salesforce using java?
Thanks in advance
How to insert the data to salesforce using java?
Thanks in advance
Use JAVA sdk for it. Reference URL : https://developer.salesforce.com/page/Java
If this answers your question mark Best Answer it as solution and then hit Like!
Thanks for your quick response.
I have tried to create the record to salesforce. But, account created in that.
This is my java code for create the record.
public String createRecord(String name, String instanceUrl, String accessToken, PrintWriter writer) throws ServletException, IOException {
String accountId = null;
CloseableHttpClient httpclient = HttpClients.createDefault();
JSONObject account = new JSONObject();
try {
account.put("Name", "Suganya");
account.put("Gender__c", "Female");
} catch (JSONException e) {
e.printStackTrace();
throw new ServletException(e);
}
HttpPost httpost = new HttpPost(instanceUrl + "/services/data/v30.0/sobjects/Account/");
httpost.addHeader("Authorization", "OAuth " + accessToken);
StringEntity messageEntity = new StringEntity(account.toString(), ContentType.create("application/json"));
httpost.setEntity(messageEntity);
// Execute the request.
CloseableHttpResponse closeableresponse = httpclient.execute(httpost);
System.out.println("Response Status line :" + closeableresponse.getStatusLine());
try {
writer.write("HTTP status " + closeableresponse.getStatusLine().getStatusCode() + " creating account\n\n");
if (closeableresponse.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) {
try {
// Do the needful with entity.
HttpEntity entity = closeableresponse.getEntity();
InputStream rstream = entity.getContent();
JSONObject authResponse = new JSONObject(new JSONTokener(rstream));
System.out.println("Create response: " + authResponse.toString(2));
if (authResponse.getBoolean("success")) {
accountId = authResponse.getString("id");
writer.write("New record id " + accountId + "\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
// throw new ServletException(e);
}
}
} finally {
httpclient.close();
}
return accountId;
}
Is this is correct or not??
Thanks in advance.