how send json content using httpurlconnection in saleforce

Home / Uncategorized / how send json content using httpurlconnection in saleforce

Question:
String uri = baseUri + "/sobjects/Lead/"+leadId;

System.out.println(uri);

HttpsURLConnection connection =null;
URL url = new URL(uri);
connection = (HttpsURLConnection) url.openConnection();
connection.setDoInput (true);
connection.setDoOutput (true);
//connection.setUseCaches (false);

connection.setRequestProperty("Authorization", "OAuth "+loginAccessToken);
connection.setRequestProperty("X-PrettyPrint", "1");

connection.setRequestProperty("Content-Type", "application/json");

connection.setRequestMethod("POST");
JSONObject lead = new JSONObject();
lead.put("LastName", "Lead –UPDATED");

OutputStreamWriter output=new OutputStreamWriter(connection.getOutputStream());
output.append(lead.toString());
output.flush();

javax.net.ssl.SSLSocketFactory sslSocketFactory = getFactorySimple();
connection.setSSLSocketFactory(sslSocketFactory);

int response1= connection.getResponseCode();

System.out.println(connection.getResponseMessage());

System.out.println(response1);

But i am getting output as follows

https://ap2.salesforce.com/services/data/v40.0/sobjec/Lead/00Q2800000YUNrXEAX Bad Request 400


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *