Created
February 1, 2016 16:48
-
-
Save leehildebrand/6142d14914679872461d to your computer and use it in GitHub Desktop.
TriggerFutureCallout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IntegrationController{ | |
@future(callout=true) | |
public static void sendShift(String[] shifts){ | |
HttpRequest req = new HttpRequest(); | |
req.setEndpoint(API__c.getValues('Endpoint').Value__c); | |
req.setTimeout(120000); | |
req.setMethod('POST'); | |
//req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(API__c.getValues('Username').Value__c+':'+API__c.getValues('Password').Value__c))); | |
req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(API__c.getValues('Username').Value__c+':'+API__c.getValues('Password').Value__c))); | |
req.setheader('Content-Type', 'text/xml'); | |
String xmlString = '<?xml version="1.0" encoding="UTF-8"?>'; | |
xmlString += '<shiftupdaterequest>'; | |
xmlString += '<apikey>'+API__c.getValues('apikey').Value__c+'</apikey>'; | |
xmlString+='<shifts>'; | |
for(String shift : shifts){ | |
String[] shift_fields = shift.split(','); | |
xmlString+='<shift>'; | |
xmlString += '<shiftid>'+shift_fields[0]+'</shiftid>'; | |
xmlString += '<tournid>'+shift_fields[1]+'</tournid>'; | |
xmlString += '<naudljudgeid>'+shift_fields[2]+'</naudljudgeid>'; | |
xmlString += '<naudljudgename>'+shift_fields[3]+'</naudljudgename>'; | |
xmlString += '<naudljudgeemail>'+shift_fields[4]+'</naudljudgeemail>'; | |
xmlString += '<status>'+shift_fields[5]+'</status>'; | |
xmlString += '<plannedstartdate>'+shift_fields[6]+'</plannedstartdate>'; | |
xmlString += '<shiftstartdate>'+shift_fields[7]+'</shiftstartdate>'; | |
xmlString += '<hoursworked>'+shift_fields[8]+'</hoursworked>'; | |
xmlString+='</shift>'; | |
} | |
xmlString+='</shifts>'; | |
xmlString += '</shiftupdaterequest>'; | |
req.setBody(xmlString); | |
system.debug('*************** what we sent: '+xmlString); | |
system.debug('********** then said: '+new Http().send(req).getBody()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment