2

I have the following class:

@RestResource(urlMapping='/myservice')
global with sharing class MyService {

    @HttpPost
    global static String newMessage() {
        RestRequest req = RestContext.request;
        System.debug(LoggingLevel.ERROR, 'MyService.newMessage body:\n ' + req.requestBody);
        return 'Testing... 1,2,3';
    }
}

I can't find the debug statement anywhere. I tried adding my user to the debug logs monitored users and tried using the Developer Console. I tried everything mentioned here: Debug not working? I know the class is running because I tested the service and I get the response "Testing... 1,2,3".

Acuariano
  • 656
  • 8
  • 20

2 Answers2

3

Following are the steps i would take to solve this issue:

  1. Sometimes the web-services are invoked by user-accounts dedicated to Integration or Web-Services. If that is true, did you try to add that user in Debug Logs?

  2. Check the the "Log Filters" for the Web-Service class.

  3. Try using System.debug() without 'LoggingLevel' Option.

  4. Its possible to miss debug logs , if there are so many debug logs generated in short period of time. Salesforce can Only hold up-to 20 request at any given time. Open Developer console before you invoke the service. Salesforce automatically refreshes the console. By this way, there are less chance to miss the Debug Log.

If you tried all the above steps and still fail to get debug logs , i would try to send a APEX email (Just for the heck of it). This is just to narrow down the issue and figure out if the issue is really with Debug Logs.

Jag
  • 1,205
  • 1
  • 8
  • 18
  • 1
    The first point was the problem. I'll add another comment explaining further. – Acuariano Dec 29 '14 at 20:49
  • In this case, the service was accessed through a Site, which runs with it's own user. Checking how you access the service is a good idea also. When in doubt, try calling the service directly through Developer Console and if the debug works there. – Acuariano Jan 06 '15 at 23:38
  • 1
    A little late to the party but I tried your solution. I added the site guest user to the debug log but it still wont print out the logs. I even cleared the log records. Any idea what is going on. – codeinprogress Apr 28 '17 at 04:24
  • 1
    Facing same issue – Shanker Paudel Jul 26 '17 at 12:42
0

I think logs are not enabled for REST Apex. I am not able to set trace flag on the REST Resource class. Although the class exists and I am able to select the class for setting the trace, I get following error when I try to save the trace flag.

Trace Flags on REST Apex

  • Welcome to Salesforce Stack Exchange (SFSE)! This is a Questions & Answers site, not a threaded forum. Yours seems to be either a comment to go under the Q or the other A, or if you need help a new question (in it, you can link to this question or its other answer for reference if you'd like - just click "Share" at the bottom left of the post to get a URL). Regardless, please read Why and how are some answers deleted?, and be aware that this "answer" will likely be deleted. – Moonpie Sep 08 '22 at 13:39