• ChandraChouksey
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Below simple code is running well in many orgs, but only the org it is throwing error "INVALID_SESSION_ID". What could be blocking here?

I'm executing it from Developer Console. 

//---------Code START--------
HttpRequest req = new HttpRequest();
string endpointUrl = System.URL.getSalesforceBaseURL().toExternalForm() + '/services/data/v37.0/tooling';
System.debug(endpointUrl);
req.setEndpoint(endpointUrl);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setMethod('GET');

Http httpreq = new Http();
HttpResponse res = httpreq.send(req);
System.debug('~~~~: \n' + res.getBody());
//--------Code END----------

Error Log:

02:59:53.1 (10411330)|CALLOUT_REQUEST|[22]|System.HttpRequest[Endpoint=https://finbetademoorg-dev-ed.my.salesforce.com/services/data/v37.0/tooling, Method=GET]
02:59:53.1 (33260982)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1007
02:59:53.1 (33671612)|CALLOUT_RESPONSE|[22]|System.HttpResponse[Status=Unauthorized, StatusCode=401]
02:59:53.1 (33700285)|HEAP_ALLOCATE|[22]|Bytes:91
02:59:53.1 (33745456)|STATEMENT_EXECUTE|[23]
02:59:53.1 (33771765)|HEAP_ALLOCATE|[23]|Bytes:7
02:59:53.1 (33851753)|HEAP_ALLOCATE|[23]|Bytes:75
02:59:53.1 (33872502)|HEAP_ALLOCATE|[23]|Bytes:82
02:59:53.1 (33899640)|USER_DEBUG|[23]|DEBUG|~~~~:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

 
Below simple code is running well in many orgs, but only the org it is throwing error "INVALID_SESSION_ID". What could be blocking here?

I'm executing it from Developer Console. 

//---------Code START--------
HttpRequest req = new HttpRequest();
string endpointUrl = System.URL.getSalesforceBaseURL().toExternalForm() + '/services/data/v37.0/tooling';
System.debug(endpointUrl);
req.setEndpoint(endpointUrl);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setMethod('GET');

Http httpreq = new Http();
HttpResponse res = httpreq.send(req);
System.debug('~~~~: \n' + res.getBody());
//--------Code END----------

Error Log:

02:59:53.1 (10411330)|CALLOUT_REQUEST|[22]|System.HttpRequest[Endpoint=https://finbetademoorg-dev-ed.my.salesforce.com/services/data/v37.0/tooling, Method=GET]
02:59:53.1 (33260982)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1007
02:59:53.1 (33671612)|CALLOUT_RESPONSE|[22]|System.HttpResponse[Status=Unauthorized, StatusCode=401]
02:59:53.1 (33700285)|HEAP_ALLOCATE|[22]|Bytes:91
02:59:53.1 (33745456)|STATEMENT_EXECUTE|[23]
02:59:53.1 (33771765)|HEAP_ALLOCATE|[23]|Bytes:7
02:59:53.1 (33851753)|HEAP_ALLOCATE|[23]|Bytes:75
02:59:53.1 (33872502)|HEAP_ALLOCATE|[23]|Bytes:82
02:59:53.1 (33899640)|USER_DEBUG|[23]|DEBUG|~~~~:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

 
Hi,

I am Calling future method from schedule apex, getting an error: System.HttpResponse[Status=Unauthorized, StatusCode=401]
I think we are getting because of UserInfo.getSessionId() null, If I comment hilighted line also I am getting same error. Is there any solution for this. or Can I schedule the callouts?

public class Sample
{
      @future(Callout = true)
      public static void getCoverageforClasses()
      {
           String objectIdQuery = 'SELECT ApexClassorTriggerId, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate';

           String environmentURL = URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/tooling/query/?q=' +      EncodingUtil.urlEncode(objectIdQuery, 'UTF-8');
     
        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint(environmentURL);
        req.setMethod('GET');
     
        Http h = new Http();
        return h.send(req).getBody();             
      }
}



Thanks
Venkat

Hi all,

            I had created a customer portal using my Developer org, but it's having some Login related  problems, whenever i try to login as new user, i first had to provide email address & on that email address salesforce provides first time password but in my case i'm only getting error messages as

------------------------------------------------------Email--------------------------------------------------------------

We appreciate your interest in registering for an account with "My company name" Customer Portal. However, your signup was not completed due to temporary technical reasons detailed below. Please contact the portal administrator if you have any questions.


Thank you,

'My company name'  Customer Support


Unfortunately, you are ineligible for registering an account at this time.

 

---------------------------------------------------------------------------------------------------------------------

 

so please provide me any solution for this.

Thanks in advance..........