A background session that is started by using the STARTSESSION Function (Sessions) can be difficult to debug because it is called by C/AL code for which you often do not have dedicated control. Therefore, you cannot debug the calling code and step through it to access the background session. To debug a background session, you must first set a breakpoint in the codeunit that runs when the session is started.
Before you begin, you must verify that no breakpoints are currently enabled in the calling code. For more information about how to view and disable breakpoints, see How to: Manage Breakpoints from the Debugger Breakpoint List.
To debug a background session
In the development environment, on the Tools menu, choose Object Designer.
In Object Designer, choose the Codeunit button, select the codeunit that is run when you start the background session, and then choose the Design button. The ID of this codeunit is the value that you pass to the STARTSESSION function in the CodeunitID parameter.
In the C/AL Editor, place the cursor on the first line of the OnRun trigger.
On the Tools menu, choose Debugger, and then choose Toggle Breakpoint. A red dot is displayed in the margin, and the breakpoint is immediately enabled.
On the Tools menu, choose Debugger, and then choose Debug Session. The Session List page opens.
On the Session List page, choose Debug Next. The debugger is now active and is waiting to attach to a session.
Start a new business session. For more information about types of business sessions, see Debugging.
In the new business session, perform the action required to call the STARTSESSION function. The background session starts and calls the codeunit in which you have set a breakpoint. The debugger breaks at the breakpoint in the background session.