Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void createUsers() {
- System.out.println("n_______________ USER INSERT _______________");
- String uri = baseUri + "/sobjects/User/";
- System.out.println(uri);
- try {
- //create the JSON object containing the new lead details.
- JSONObject lead = new JSONObject();
- lead.put("FirstName", "Jake");
- lead.put("LastName", "sully");
- lead.put("Alias", "Jake");
- lead.put("Email", "Jake@gmail.com");
- lead.put("Username", "Jake@gmail.com");
- lead.put("Name", "jake");
- lead.put("UserRoleId","00E28000000oD8EEAU");
- lead.put("Id", "10028000000GLSIAA4");
- lead.put("EmailEncodingKey", "ISO-8859-1");
- lead.put("TimeZoneSidKey", "Asia/Kolkata");
- lead.put("LocaleSidKey", "en_US");
- lead.put("ProfileId", "00e280000027hnGAAQ");
- lead.put("LanguageLocaleKey", "en_US");
- //Construct the objects needed for the request
- HttpClient httpClient = HttpClientBuilder.create().build();
- HttpPost httpPost = new HttpPost(uri);
- httpPost.addHeader(oauthHeader);
- httpPost.addHeader(prettyPrintHeader);
- // The message we are going to post
- StringEntity body = new StringEntity(lead.toString(1));
- body.setContentType("application/json");
- httpPost.setEntity(body);
- //Make the request
- HttpResponse response = httpClient.execute(httpPost);
- //Process the results
- System.out.println(response.toString());
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == 201) {
- String response_string = EntityUtils.toString(response.getEntity());
- JSONObject json = new JSONObject(response_string);
- // Store the retrieved lead id to use when we update the lead.
- leadId = json.getString("id");
- } else {
- System.out.println("Insertion unsuccessful. Status code returned is " + statusCode);
- }
- } catch (JSONException e) {
- System.out.println("Issue creating JSON or processing results");
- e.printStackTrace();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } catch (NullPointerException npe) {
- npe.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement