5

We are doing salesforce to salesforce integration using REST API(both are developer edition),

Problem is : I am not getting access_token in response and it's look like

"access_token": "SESSION_ID_REMOVED",

public class CallOutToNiharCsInstance {

    String clientId     = EncodingUtil.urlEncode('ABCD1234','UTF-8');
    String clientSecret = EncodingUtil.urlEncode('123456','UTF-8');
    String username     = EncodingUtil.urlEncode('[email protected]','UTF-8');
    String password     = EncodingUtil.urlEncode('abc#123_Security_Token','UTF-8');

    public void callOutMethod(){
        String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setBody(reqbody);
        req.setMethod('POST');
        req.setEndpoint('https://ap1.force.com/services/oauth2/authorize');
        HttpResponse res = h.send(req);
        system.debug('Response is ::::::::' + res);
        system.debug('Body Is ::::::::::::' + res.getBody());
    }

}

Another class

public void storeAccessToken(){
    system.debug('URL Is ******' + System.URL.getSalesforceBaseURL());
    system.debug('URL Is ******' + System.URL.getSalesforceBaseURL().getHost());

    if(ApexPages.currentPage().getParameters().get('code') != null) {
        String reqbody = 'grant_type=authorization_code&client_id='+clientId+'&client_secret='+clientSecret+'&code='+ApexPages.currentPage().getParameters().get('code')+'&redirect_uri=https://c.ap5.visual.force.com/apex/StoreAccessToken';
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setBody(reqbody);
        req.setMethod('POST');
        req.setEndpoint('https://ap1.force.com/services/oauth2/token');
        HttpResponse res = h.send(req);
        system.debug('Response is ::::::::' + res);
        system.debug('Body Is ::::::::::::' + res.getBody());
    }
}
3
  • 2
    Session token is hidden now from debug logs. It is in variable, but removed from logs. How to check that -- system.assertEquals(null, res.getBody() ); will lead to exception, which shows that there is a access token
    – kurunve
    Jul 28, 2017 at 7:38
  • You mean access token is available in response, it just hide from the debug log, right ?
    – Nail David
    Jul 28, 2017 at 7:41
  • yes. That appeared on Summer'17
    – kurunve
    Jul 28, 2017 at 8:40

1 Answer 1

8

You can't see a direct Session ID in the debug logs for security reasons. See Session_ID_Remove Issue in API callouts in Salesforce.

However, it should still be possible to use it for call outs.

If you really want to see the value in the debug logs then you can alter it slightly to it doesn't appear as a valid session id.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .