{"title":"Session.StartSession(var Integer, Integer [, Text] [, var Record]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/session/session-startsession-integer-integer-string-table-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-startsession-integer-integer-string-table-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-startsession-integer-integer-string-table-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Starts a session without a UI and runs the specified codeunit.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Session.StartSession(var Integer, Integer [, Text] [, var Record]) Method","slug":"sessionstartsessionvar-integer-integer-text-var-record-method","at":0,"chars":3571},{"level":2,"title":"Syntax","slug":"syntax","at":199,"chars":212},{"level":2,"title":"Parameters","slug":"parameters","at":411,"chars":701},{"level":2,"title":"Return Value","slug":"return-value","at":1112,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":1350,"chars":1652},{"level":3,"title":"Dialog box behavior","slug":"dialog-box-behavior","at":1994,"chars":1008},{"level":2,"title":"Example","slug":"example","at":3002,"chars":434},{"level":2,"title":"Related information","slug":"related-information","at":3436,"chars":135}],"text":"# Session.StartSession(var Integer, Integer [, Text] [, var Record]) Method\n> Version: _Available or changed with runtime version 1.0._\nStarts a session without a UI and runs the specified codeunit.\n## Syntax\n```al\n[Ok := ]  Session.StartSession(var SessionId: Integer, CodeunitId: Integer [, Company: Text] [, var Record: Record])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nSessionId\nType: ../integer/integer-data-type\nThe ID of the new session that is started. The ID is assigned to the SessionID variable after the session is started successfully. This parameter is passed by reference to the method.\nCodeunitId\nType: ../integer/integer-data-type\nThe ID of the codeunit to run when the session is started.\n*[Optional] Company*\nType: ../text/text-data-type\nThe company in which to start the session. By default, the session is started in the same company as the calling session.\n*[Optional] Record*\nType: ../record/record-data-type\nA record that is passed to the OnRun trigger of the codeunit that runs when the session is started. This parameter is optional.\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nThe session is started on the same Business Central instance from which the method is called. The session that is started is a background session and therefore has no UI. The session executes using the same user credentials as the calling AL code.\nEach background session has the same impact on resources as a regular user session. In addition, it takes time and resources to start each background session. Therefore, we recommend that you consider when and how you use background sessions. For example, do not use background sessions for small tasks that occur often because the cost of starting the session for each tasks is high.\n### Dialog box behavior\nThe following table describes how dialog boxes are handled in a background or web service session, which has no UI.\nMethod that creates the dialog box|Behavior\n../dialog/dialog-confirm-method|- Dialog box is suppressed.<br />- The following error occurs on the Business Central instance: Business Central attempted to issue a client callback to show a confirmation dialog box.\n../dialog/dialog-error-string-joker-method|- Dialog box is suppressed.<br />- AL code execution ends.<br />- The error is logged to the event log of the Business Central instance.<br />- The error is added to the Comments field of the Session Event table.\n../dialog/dialog-message-method|- Dialog box is suppressed.<br />- The message is recorded in the event log of the computer that is running Business Central instance. The log entry has type Information and includes the context of the message.\n../dialog/dialog-open-method|- Dialog box is suppressed.<br />- Dialog box text is not displayed or logged.\n## Example\nIn this example, the Cache Stress Test codeunit is a custom codeunit.\n```al\nvar\n    CacheStressTestRec: Record Customer;\n    SessionID: Integer;\n    OK: Boolean;\nbegin\n    OK := StartSession(SessionId, CodeUnit::\"Cache Stress Test\", CompanyName, CacheStressTestRec);\n    if OK then\n      StopSession(SessionId, 'Logoff cache stress test session')\n    else\n      Error('The session was not started successfully.');\nend;\n```\n## Related information\nsession-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}