Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String endpoint='https://test.salesforce.com/services/oauth2/token';
- String username = 'username';
- String password = 'password';
- String ClientId= 'abcdefgh';
- String ClientSecret = 'xyz234890';
- Httprequest req = new HttpRequest();
- req.setMethod('POST');
- req.setHeader('Content-Type','application/x-www-form-urlencoded');
- req.setBody('grant_type=password' +
- '&client_id=' + ClientId +
- '&client_secret=' + ClientSecret +
- '&username=' + username +
- '&password=' + password
- );
- req.setEndpoint(endpoint);
- Http http = new Http();
- HttpResponse res;
- try {
- res = http.send(req);
- system.debug('body:'+res.getBody());
- }catch(system.CalloutException e){
- system.debug('error'+e);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement