function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SKiranSKiran 

REST services in salesforce dev org.

I have tried to access sobject through force workbench rest explorer via "/services/data/v28.0/sobjects"

and I was getting data.

Now I am trying to get data from apex also using following code.

Httprequest request = new Httprequest();
request.setEndpoint('https://ap1.salesforce.com/services/data/v28.0/sobjects');
request.setMethod('GET');
request.setHeader('ACCEPT', 'application/json');

request.setHeader('Authorization','AOuth'+UserInfo.getSessionId());
System.debug('DEBUG-->sessionID'+UserInfo.getSessionId());
try {
    System.debug('before calling invoke api for ');  
    Http http = new Http();
    String getResponseString = ''+http.send(request).getBody();
    System.debug('getResponseString------'+getResponseString);
} catch(Exception e){
    System.debug('Exception++++=='+e);
}

 

but I am getting error like {"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}

 

Note: I have added https://ap1.salesforce.com in remote site settings.

 

I might be doing something wrong in code or I might need to activate something in org to get this working. Any pointers would be so helpful. Thanks in advance.