Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //method to make callout and get the response
- @future(callout=true)
- Public static void UpsertLeads(){
- //String variable to store the end point url
- String endPoint= 'https://www.***********.com.au/webservice/UpsideDownService/';
- //String to store the password
- String Password ='**_*_*_*_*_*';
- //String to Store the UserName
- String UserName='******';
- //String to Store the EndDate
- Datetime StartDate = system.now().addHours(-2);
- //String to Store the Startdate
- Datetime EndDate = system.now();
- //String Store the Encrypted password in Md5
- String EncryptedPassword = EncodingUtil.convertToHex(crypto.generateDigest('MD5',Blob.valueOf(Password)));
- // String to store the body of request to sent
- String body = '<request><login>'+UserName+'</login><password>'+EncryptedPassword+'</password><startDate>'+StartDate+'</startDate><endDate>'+EndDate+'</endDate></request>';
- System.debug('Body For Request'+body);
- //Http request variable to send the request
- HttpRequest req = new HttpRequest();
- //setting the endPoint
- req.setEndpoint(endPoint);
- //setting the method
- req.setMethod('POST');
- //setting the body
- req.setBody(body);
- Http http = new Http();
- //http response variable
- HTTPResponse response;
- //get the response
- response = http.send(req);
- System.debug('@$ response ' + response);
- System.debug('@$ response.getBody() ' + response.getBody());
- System.debug('@$ response.getBodyDocument() ' + response.getBodyDocument());
- //to read xml
- dom.Document docx = response.getBodyDocument();
- //Creating object
- LeadParser leadParserObject = new LeadParser();
- List<Lead> newLeads = leadParserObject.parseLead(docx);
- System.debug('@$ newLeads ' + newLeads);
- if(newLeads != null && !newLeads.isEmpty()){
- Database.insert(newLeads,false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement