Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. if (customer.thisOrg.domain_override__c!=null) {
  2. req.setEndpoint(customer.thisOrg.domain_override__c+'/services/oauth2/token');
  3. }
  4. else {
  5. //check to see if type is sandbox or production/developer
  6. if(customer.thisOrg.type__c == 'Sandbox'){
  7. req.setEndpoint('https://test.salesforce.com/services/oauth2/token');
  8. }
  9. else{
  10. req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
  11. }
  12. }
  13. req.setMethod('POST');
  14. req.setBody('grant_type=password'+
  15. '&client_id='+' CLIENT_ID'+
  16. '&client_secret='+'CLIENT_SECRET'+
  17. '&username='+customer.thisOrg.username__c+
  18. '&password='+customer.thisOrg.password__c
  19. );
  20.  
  21. httpResponse res = new httpResponse();
  22.  
  23. try {
  24. // send request
  25. Http http = new Http();
  26. // capture response
  27. res = http.send(req);
  28. system.debug('authentication response: '+ res.getBody());
  29. }
  30. catch (exception e) {
  31. system.debug('error authenticating with customer: '+ e.getMessage());
  32. customer.log += 'nn error authenticating: ' + e.getMessage();
  33. return null;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement