{"title":"CodeCop Info AA0235","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0235/","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/analyzers/codecop-aa0235, 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/analyzers/codecop-aa0235","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":"When using trigger 'OnInstallAppPerCompany' in a codeunit with 'Subtype = Install' you should also add a 'Company-Initialize'::'OnCompanyInitialize' event subscriber to ensure that new companies also have the correct setup.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"CodeCop Info AA0235","slug":"codecop-info-aa0235","at":0,"chars":1390},{"level":2,"title":"Description","slug":"description","at":140,"chars":239},{"level":2,"title":"Reason for the rule","slug":"reason-for-the-rule","at":379,"chars":403},{"level":2,"title":"Bad code example","slug":"bad-code-example","at":782,"chars":145},{"level":2,"title":"Good code example","slug":"good-code-example","at":927,"chars":326},{"level":2,"title":"Related information","slug":"related-information","at":1253,"chars":137}],"text":"# CodeCop Info AA0235\nWhen using 'OnInstallAppPerCompany' you should also add 'Company-Initialize'::'OnCompanyInitialize' event subscriber.\n## Description\nWhen using trigger 'OnInstallAppPerCompany' in a codeunit with 'Subtype = Install' you should also add a 'Company-Initialize'::'OnCompanyInitialize' event subscriber to ensure that new companies also have the correct setup.\n## Reason for the rule\n'OnInstallAppPerCompany' is only run on companies that exist when installing the extension. Many extensions were missing a 'OnCompanyInitialize' subscription, so companies that were created after the extension installation were missing setup that the extension should do. For example, insertion of records in some tables was done only for existing companies and not for new ones.\n## Bad code example\n```al\ncodeunit 1160 \"AP Install\"\n{\n   Subtype = Install;\n\n   trigger OnInstallAppPerCompany()\n\n   begin\n   ...\n   end;\n}\n```\n## Good code example\n```al\ncodeunit 1160 \"AP Install\"\n{\n   Subtype = Install;\n\n   trigger OnInstallAppPerCompany()\n\n   begin\n   ...\n   end;\n\n   [EventSubscriber(ObjectType::Codeunit, Codeunit::\"Company-Initialize\", 'OnCompanyInitialize', '', false, false)]\n   local procedure CompanyInitialize()\n   begin\n   ...\n   end;\n}\n```\n## Related information\nCodeCop Analyzer<codecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}