Hi Abhishek,
You can get the session id using this:-
String sessionID = UserInfo.getSessionId();
You can get the accessToken using this:-
Create connected app then fill all the details then call this https method it will provide you access token
public final String clientId =”;
public final string clientSecret=”;
public final String userName = ”;
public final String password = ”;
HttpRequest req = new HttpRequest();
req.setMethod(‘POST’);
req.setEndpoint(endPointUrl);
req.setBody(‘grant_type=password’ +
‘&client_id=’+ clientId +
‘&client_secret=’+ clientSecret +
‘&username=’ + EncodingUtil.urlEncode(userName, ‘UTF-8’) +
‘&password=’ + EncodingUtil.urlEncode(password, ‘UTF-8’));
Http h = new Http();
Httpresponse res = h.send(req);
string body = res.getBody();
system.debug(‘***** Body — ‘+ body);
wrapperForHttp wObj = (wrapperForHttp)Json.deserialize(body,wrapperForHttp.class);
string accessToken = wObj.access_token;
system.debug(‘***** accessToken — ‘+ accessToken);
Hope this help you..
-
This reply was modified 8 years, 4 months ago by
Piyush.