Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. //method to make callout and get the response
  2. @future(callout=true)
  3. Public static void UpsertLeads(){
  4.  
  5. //String variable to store the end point url
  6. String endPoint= 'https://www.***********.com.au/webservice/UpsideDownService/';
  7.  
  8. //String to store the password
  9. String Password ='**_*_*_*_*_*';
  10.  
  11. //String to Store the UserName
  12. String UserName='******';
  13.  
  14. //String to Store the EndDate
  15. Datetime StartDate = system.now().addHours(-2);
  16.  
  17. //String to Store the Startdate
  18. Datetime EndDate = system.now();
  19.  
  20. //String Store the Encrypted password in Md5
  21. String EncryptedPassword = EncodingUtil.convertToHex(crypto.generateDigest('MD5',Blob.valueOf(Password)));
  22.  
  23. // String to store the body of request to sent
  24. String body = '<request><login>'+UserName+'</login><password>'+EncryptedPassword+'</password><startDate>'+StartDate+'</startDate><endDate>'+EndDate+'</endDate></request>';
  25. System.debug('Body For Request'+body);
  26. //Http request variable to send the request
  27. HttpRequest req = new HttpRequest();
  28.  
  29. //setting the endPoint
  30. req.setEndpoint(endPoint);
  31.  
  32. //setting the method
  33. req.setMethod('POST');
  34.  
  35. //setting the body
  36. req.setBody(body);
  37.  
  38.  
  39. Http http = new Http();
  40.  
  41. //http response variable
  42. HTTPResponse response;
  43.  
  44.  
  45. //get the response
  46. response = http.send(req);
  47.  
  48. System.debug('@$ response ' + response);
  49. System.debug('@$ response.getBody() ' + response.getBody());
  50. System.debug('@$ response.getBodyDocument() ' + response.getBodyDocument());
  51.  
  52. //to read xml
  53. dom.Document docx = response.getBodyDocument();
  54.  
  55. //Creating object
  56. LeadParser leadParserObject = new LeadParser();
  57.  
  58. List<Lead> newLeads = leadParserObject.parseLead(docx);
  59. System.debug('@$ newLeads ' + newLeads);
  60. if(newLeads != null && !newLeads.isEmpty()){
  61. Database.insert(newLeads,false);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement