Guest User

Untitled

a guest
Jun 13th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. public class ProcessHandlerShowAccounts {
  2. public class AccountParameter {
  3. @InvocableVariable(required=true)
  4. public Id accountId;
  5. @InvocableVariable(required=true)
  6. public String name;
  7. }
  8.  
  9. @InvocableMethod(label='handleNewAccounts' description='Send the Accounts variables passed from Process Builder to the webservice')
  10. public static void handleNewAccounts(AccountParameter [] accountParameters) {
  11. //I am unable to see the debug
  12. System.debug('Account ID VALUE: '+ accountParameters[0].accountId);
  13. System.debug('Name Value: '+accountParameters[0].name);
  14. webServiceCallOut(accountParameters[0].accountId,accountParameters[0].name);
  15. }
  16.  
  17. @future(callout=true)
  18. public static void webServiceCallOut(ID n, String a) {
  19. Http http = new Http();
  20. HttpRequest req = new HttpRequest();
  21. HttpResponse res = new HttpResponse();
  22.  
  23. req.setEndpoint('https://namer/Accounts'+' sfdcid='+n+'&operation='+a);
  24.  
  25. String username = 'test';
  26. String password ='123';
  27. Blob headerValue = Blob.valueOf(username + ':' + password);
  28. String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
  29.  
  30. req.setHeader('Authorization', authorizationHeader);
  31. req.setMethod('POST');
  32. //Create a new Http object to send the request object
  33. //a response object is generated as a result
  34.  
  35. try {
  36. res = http.send(req);
  37.  
  38. if(res.getStatus()=='200') {
  39. System.debug('GET BODY: '+ res.getBody());
  40. } else {
  41. System.debug('GET Status Else: '+res.getStatus());
  42. }
  43. } catch(System.CalloutException e) {
  44. System.debug('Callout error: '+ e);
  45. System.debug(res.toString());
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment