Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. trigger Intglead on Lead (After Insert) {
  2. List<string> lsstr= new List<string>();
  3. for(Lead xt:Trigger.new)
  4. {
  5. lsstr.add(String.valueOf(xt.LastName));
  6. lsstr.add(String.valueOf(xt.Company));
  7. lsstr.add(String.valueOf(xt.Status));
  8. }
  9. SendLeadUsingRESTAPI.callcreateAcc(lsstr);
  10. }
  11. source class:
  12. public class SendLeadUsingRESTAPI {
  13. private final String clientId = '3MVG9uudbyLbNPZOx9ecDD3I5eBJPDJt5Iy2Hn7gluNe0G_pabcaK0kzn3A3KnEnpzEQOEHFmWhhHCodCXaf0';
  14. private final String clientSecret = 'xxxxxx';
  15. private final String username = 'xxxxxxxx';
  16. private final String password = 'xxxxxxxxx';
  17. public class deserializeResponse
  18. {
  19. public String id;
  20. public String access_token;
  21. }
  22. public String ReturnAccessToken (SendLeadUsingRESTAPI leada)
  23. {
  24. String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
  25. Http h = new Http();
  26. HttpRequest req = new HttpRequest();
  27. req.setBody(reqbody);
  28. req.setMethod('POST');
  29. req.setEndpoint('https://na30.salesforce.com/services/oauth2/token');
  30. HttpResponse res = h.send(req);
  31. deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
  32. return resp1.access_token;
  33. }
  34. @future(callout=true)
  35. public static void callcreateAcc (List<String> l)
  36. {
  37. List<string> js = new List<string>();
  38. SendLeadUsingRESTAPI leadb = new SendLeadUsingRESTAPI();
  39. String accessToken;
  40. accessToken = leadb.ReturnAccessToken(leadb);
  41. for(string s : l)
  42. {
  43. js.add(s);
  44. }
  45. if(accessToken != null){
  46. String endPoint = 'https://na30.salesforce.com/services/apexrest/Lead/doPost';
  47. String jsonstr = (String)JSON.serialize(js);
  48. System.debug('hello'+jsonstr);
  49. Http h2 = new Http();
  50. HttpRequest req1 = new HttpRequest();
  51. req1.setHeader('Authorization','Bearer ' + accessToken);
  52. req1.setHeader('Content-Type','application/json');
  53. req1.setHeader('accept','application/json');
  54. req1.setBody(jsonstr);
  55. req1.setMethod('POST');
  56. req1.setEndpoint(endPoint);
  57. HttpResponse res1 = h2.send(req1);
  58. }
  59. }
  60. }
  61. target class:
  62. @RestResource(urlMapping='/Lead/doPost')
  63. global with sharing class MyRestResource {
  64. @HttpPost
  65. global static String doPost(String name,
  66. String Company, String Status) {
  67. Lead ld = new Lead();
  68. ld.LastName = name;
  69. ld.Company = Company;
  70. ld.Status = Status;
  71. insert ld;
  72. return ld.Id;
  73. }
  74. }
  75.  
  76. 12:44:02.19 (413305091)|VARIABLE_ASSIGNMENT|[35]|endPoint|"https://na30.salesfo (37 more) ..."
  77. 12:44:02.19 (413307102)|STATEMENT_EXECUTE|[36]
  78. 12:44:02.19 (413317598)|METHOD_ENTRY|[36]||System.JSON.serialize(Object)
  79. 12:44:02.19 (413643659)|METHOD_EXIT|[36]||System.JSON.serialize(Object)
  80. 12:44:02.19 (413650492)|VARIABLE_SCOPE_BEGIN|[36]|jsonstr|String|false|false
  81. 12:44:02.19 (413662132)|VARIABLE_ASSIGNMENT|[36]|jsonstr|"["youtest7","rt7","N (4 more) ..."
  82. 12:44:02.19 (413665227)|STATEMENT_EXECUTE|[37]
  83. 12:44:02.19 (413668691)|HEAP_ALLOCATE|[37]|Bytes:5
  84. 12:44:02.19 (413685019)|HEAP_ALLOCATE|[37]|Bytes:29
  85. 12:44:02.19 (413723066)|USER_DEBUG|[37]|DEBUG|hello["youtest7","rt7","New"]
  86. 12:44:02.19 (413730586)|STATEMENT_EXECUTE|[38]
  87. 12:44:02.19 (413751628)|VARIABLE_SCOPE_BEGIN|[38]|h2|System.Http|true|false
  88. 12:44:02.19 (413791469)|VARIABLE_ASSIGNMENT|[38]|h2|"System.Http[]"|0x76c7719a
  89. 12:44:02.19 (413795785)|STATEMENT_EXECUTE|[39]
  90. 12:44:02.19 (413810854)|VARIABLE_SCOPE_BEGIN|[39]|req1|System.HttpRequest|true|false
  91. 12:44:02.19 (413849167)|VARIABLE_ASSIGNMENT|[39]|req1|"System.HttpRequest[Endpoint=null, Method=null]"|0x42bcd6d0
  92. 12:44:02.19 (413853947)|STATEMENT_EXECUTE|[40]
  93. 12:44:02.19 (413858158)|HEAP_ALLOCATE|[40]|Bytes:13
  94. 12:44:02.19 (413861861)|HEAP_ALLOCATE|[40]|Bytes:7
  95. 12:44:02.19 (413868267)|HEAP_ALLOCATE|[40]|Bytes:119
  96. 12:44:02.19 (413926757)|STATEMENT_EXECUTE|[41]
  97. 12:44:02.19 (413931817)|HEAP_ALLOCATE|[41]|Bytes:12
  98. 12:44:02.19 (413935344)|HEAP_ALLOCATE|[41]|Bytes:16
  99. 12:44:02.19 (413965572)|STATEMENT_EXECUTE|[42]
  100. 12:44:02.19 (413969978)|HEAP_ALLOCATE|[42]|Bytes:6
  101. 12:44:02.19 (413997079)|STATEMENT_EXECUTE|[43]
  102. 12:44:02.19 (414026520)|STATEMENT_EXECUTE|[44]
  103. 12:44:02.19 (414051825)|STATEMENT_EXECUTE|[45]
  104. 12:44:02.19 (414072712)|STATEMENT_EXECUTE|[46]
  105. 12:44:02.19 (416325080)|CALLOUT_REQUEST|[46]|System.HttpRequest[Endpoint=https://na30.salesforce.com/services/apexrest/Lead/doPost, Method=POST]
  106. 12:44:02.19 (500457659)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:389
  107. 12:44:02.19 (500534441)|CALLOUT_RESPONSE|[46]|System.HttpResponse[Status=Bad Request, StatusCode=400]
  108. 12:44:02.19 (500557728)|HEAP_ALLOCATE|[46]|Bytes:120
  109. 12:44:02.19 (500589704)|VARIABLE_SCOPE_BEGIN|[46]|res1|System.HttpResponse|true|false
  110. 12:44:02.19 (500666784)|VARIABLE_ASSIGNMENT|[46]|res1|"System.HttpResponse[Status=Bad Request, StatusCode=400]"|0x68aa2c88
  111. 12:44:02.500 (500691680)|CUMULATIVE_LIMIT_USAGE
  112. 12:44:02.500 (500691680)|LIMIT_USAGE_FOR_NS|(default)|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement