Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class LeadPriorityClass {
- public static boolean isApexTest = false;
- @future (callout=true)
- public static void makePostCallout(id lid) {
- lead l = [Queries Relevant Lead Fields];
- Http http = new Http();
- HttpRequest request = new HttpRequest();
- request.setEndpoint('ENDPOINT');
- request.setMethod('POST');
- request.setHeader('Content-Type', 'application/json;charset=UTF-8');
- //set Payload Variables
- string payload = // Payload generation
- request.setBody(payload);
- system.debug('Payload: '+payload);
- //Set credentials
- String username = 'XXX';
- String password = 'XXX';
- Blob headerValue = Blob.valueOf(username + ':' + password);
- String authorizationHeader = 'BASIC '+EncodingUtil.base64Encode(headerValue);
- request.setHeader('Authorization',authorizationHeader);
- HttpResponse response = http.send(request);
- // Parse the JSON response
- if (response.getStatusCode() != 200) {
- System.debug('The status code returned was not expected: ' +
- response.getStatusCode() + ' ' + response.getStatus());
- } else {
- decimal Pf = null;
- System.debug(response.getBody());
- JSONParser parser = JSON.createParser(response.getBody());
- while (parser.nextToken() != null){
- if ((parser.getCurrentToken() == JSONToken.Field_name)){
- string fieldName = parser.getText();
- parser.nextToken();
- if(fieldName == 'probability_1'){
- fieldName = parser.gettext();
- system.debug('Prob: '+fieldName);
- pf = decimal.valueOf(fieldname);
- l.pscore__c = pf.setScale(3);
- l.last_scored__c = datetime.now();
- }
- }
- }
- update l;
- }
- //system.debug('Parsed: '+JSON2Apex.parse(response.getbody()));
- // system.debug('Probability: ');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement