Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. public static void createUsers() {
  2. System.out.println("n_______________ USER INSERT _______________");
  3.  
  4. String uri = baseUri + "/sobjects/User/";
  5. System.out.println(uri);
  6. try {
  7.  
  8.  
  9. //create the JSON object containing the new lead details.
  10. JSONObject lead = new JSONObject();
  11. lead.put("FirstName", "Jake");
  12. lead.put("LastName", "sully");
  13. lead.put("Alias", "Jake");
  14. lead.put("Email", "Jake@gmail.com");
  15. lead.put("Username", "Jake@gmail.com");
  16. lead.put("Name", "jake");
  17. lead.put("UserRoleId","00E28000000oD8EEAU");
  18. lead.put("Id", "10028000000GLSIAA4");
  19. lead.put("EmailEncodingKey", "ISO-8859-1");
  20. lead.put("TimeZoneSidKey", "Asia/Kolkata");
  21. lead.put("LocaleSidKey", "en_US");
  22. lead.put("ProfileId", "00e280000027hnGAAQ");
  23. lead.put("LanguageLocaleKey", "en_US");
  24.  
  25.  
  26. //Construct the objects needed for the request
  27. HttpClient httpClient = HttpClientBuilder.create().build();
  28.  
  29. HttpPost httpPost = new HttpPost(uri);
  30. httpPost.addHeader(oauthHeader);
  31. httpPost.addHeader(prettyPrintHeader);
  32. // The message we are going to post
  33. StringEntity body = new StringEntity(lead.toString(1));
  34. body.setContentType("application/json");
  35. httpPost.setEntity(body);
  36.  
  37. //Make the request
  38. HttpResponse response = httpClient.execute(httpPost);
  39.  
  40. //Process the results
  41. System.out.println(response.toString());
  42. int statusCode = response.getStatusLine().getStatusCode();
  43. if (statusCode == 201) {
  44. String response_string = EntityUtils.toString(response.getEntity());
  45. JSONObject json = new JSONObject(response_string);
  46. // Store the retrieved lead id to use when we update the lead.
  47. leadId = json.getString("id");
  48.  
  49. } else {
  50. System.out.println("Insertion unsuccessful. Status code returned is " + statusCode);
  51. }
  52. } catch (JSONException e) {
  53. System.out.println("Issue creating JSON or processing results");
  54. e.printStackTrace();
  55. } catch (IOException ioe) {
  56. ioe.printStackTrace();
  57. } catch (NullPointerException npe) {
  58. npe.printStackTrace();
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement