Guest User

Untitled

a guest
Mar 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. String endpoint='https://login.salesforce.com/services/oauth2/token';
  2.  
  3. String username = 'USER NAME HERE of X org';
  4. String password = 'PASSWORD without security token';
  5. String ClientId= 'connected app on Z org';
  6. String ClientSecret = 'xxxxxx';
  7.  
  8. Httprequest req = new HttpRequest();
  9. req.setMethod('POST');
  10. req.setHeader('Content-Type','application/x-www-form-urlencoded');
  11.  
  12. req.setBody('grant_type=password' +
  13. '&client_id=' + ClientId +
  14. '&client_secret=' + ClientSecret +
  15. '&username=' + username +
  16. '&password=' + password
  17. );
  18. req.setEndpoint(endpoint);
  19. Http http = new Http();
  20. HttpResponse res;
  21.  
  22. try {
  23. res = http.send(req);
  24. system.debug('body:'+res.getBody());
  25. }catch(system.CalloutException e){
  26. system.debug('error'+e);
  27. }
Add Comment
Please, Sign In to add comment