ApexLog al = [SELECT Id, LogUserId, LogUser.Name, Request, Operation, Application, Status, StartTime, Location, LogLength FROM ApexLog LIMIT 1];
String logId = al.Id;

// Set HTTPRequest Method
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/sobjects/ApexLog/' + logId + '/Body');

// Web service call
Http http = new Http();
HTTPResponse res = http.send(req);

Could someone tell why is this happening? Also the status code is 404

  • Your endpoint is incorrect - see doc: developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/…
    – identigral
    Jun 21 at 19:05
  • Using the same syntax as specified on the site..could you help? What should be the correct endpoint?
    – dexxter_7
    Jun 21 at 20:30
  • Now using: req.setEndpoint(Url.getSalesforceBaseUrl().toExternalForm() + '/services/data/v55.0/tooling/sobjects/ApexLog/' + logId + '/Body/'); Getting Error: Log Deleted
    – dexxter_7
    Jun 21 at 20:53
  • Looks like you've just answered your own question - feel free to write it up as the answer and accept it.
    – identigral
    Jun 21 at 20:54
  • Hi I am still getting an error : "Failed to load data Log from Salesforce.com: Salesforce automatically deletes system logs 24 hours after they're generated. If the log you had open was less than 24 hours old, someone deleted it. To save logs, select File > Download Log." However using the query editor I can see there are logs available.
    – dexxter_7
    Jun 21 at 21:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.