· 7 years ago · Feb 01, 2019, 06:48 AM
1String username = '****@gmail.com';
2String password = '***********WwmQ***';
3String endPoint = 'https://test.salesforce.com/services/oauth2/token';
4String clientid = '****************';
5String clientsecret = '****************8';
6Http http = new Http();
7HttpRequest req = new HttpRequest();
8req.setEndpoint(endPoint);
9req.setMethod('POST');
10req.setHeader('Content-Type','application/json');
11req.setBody('grant_type=password'+'&client_id='+clientid+'&client_secret='+clientsecret +'&username='+username+'&password='+password);
12HttpResponse res = http.send(req);
13System.debug('Body ' + res.getStatusCode());