Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. string JSONstr='';
  2. List<HCPRequest> conWrapList = new List<HCPRequest>();
  3. HCPRequest tempcontactWrapper = new HCPRequest();
  4. tempcontactWrapper.fname='Abhey';
  5. tempcontactWrapper.lname='Singh';
  6. tempcontactWrapper.countryCode='AUS';
  7. tempcontactWrapper.hcpEmail=contact.Email;
  8. conWrapList.add(tempcontactWrapper);
  9.  
  10. JSONstr = JSON.serializePretty(conWrapList);
  11. System.debug('n******'+JSONstr +'n******');
  12.  
  13. String clientId = 'xy';
  14. String clientSecret = 'x';
  15.  
  16. //We can also store our username password in custom setting.
  17. String username='x';//salesforce username
  18. String password='x';//password+securitytoken
  19. // Generating the Access Token
  20. HttpRequest req = new HttpRequest();
  21. req.setMethod('POST');
  22. req.setEndpoint('https://test.salesforce.com/services/oauth2/token');// this is the OAuth endpoint where this request will be hit
  23. req.setBody('grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password);
  24.  
  25. Http http = new Http();
  26. HTTPResponse res = http.send(req);
  27. String str = res.getBody();
  28. wrapObj = (Wrapper)Json.deserialize(str,Wrapper.class);
  29. accessToken = wrapObj.access_token;
  30. instanceUrl = wrapObj.instance_url;
  31.  
  32. HttpRequest req1 = new HttpRequest();
  33. string response='';
  34. req1.setMethod('POST');
  35. //req.setEndpoint(wrapObj.instance_url+'/services/apexrest/Account/getAccountById?name=champaKAli');
  36. string EndPt = 'y';
  37. string email='test@test.com';
  38. req1.setEndpoint(EndPt);
  39. req1.setHeader('Authorization', 'OAuth '+wrapObj.access_token);
  40. req1.setHeader('Content-Type', 'application/json');
  41. //req1.setBody('{"request":{"lname" : "Singh","hcpZipCode" : null,"hcpState" : null,"hcpEmail" : "test@test.com","hcpCity" : null,"hcpAddLine1" : null,"fname" : "Abhey","countryCode" : "AUS"}}');
  42. req1.setBody('{"request":'+JSON.Serialize(conWrapList)+'}');
  43. //req.setBody('{"request": {"countryCode": "AUS","hcpEmail" : ""+email}}');
  44.  
  45. //req.setTimeout(60000);
  46.  
  47.  
  48.  
  49. //req.setHeader('Content-Length', '0');
  50. Http http1 = new Http();
  51. HTTPResponse res1 = http1.send(req1);
  52.  
  53. System.debug('***Response***** ' + res1.getBody());
  54. if(res1.getBody()!=null)
  55. {
  56. response=res1.getBody();
  57. HCPResponse saj=(HCPResponse)JSON.deserialize(response,HCPResponse.class);
  58. System.debug('***Response came full***** ' + saj);
  59. System.debug('***Response came***** ' + saj.accList);
  60.  
  61. for(HCPResponseDetail s :saj.accList)
  62. {
  63. System.debug('***Response email***** ' + s.hcpEmail);
  64. System.debug('***Response add2***** ' + s.hcpAddrLine2);
  65. contact.Address1_Line2__c=s.hcpAddrLine2;
  66. }
  67.  
  68.  
  69. //return response;
  70. //string methodcall=methodGet(JSONstr);
  71.  
  72.  
  73. return Page.opptyStep2CustomReg;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement