{"title":"RecordRef.Count() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/recordref/recordref-count-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/recordref/recordref-count-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/recordref/recordref-count-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":"Counts the number of records that are in the filters that are currently applied to the table referred to by the RecordRef.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":183,"chars":116},{"level":2,"title":"Parameters","slug":"parameters","at":299,"chars":100},{"level":2,"title":"Return Value","slug":"return-value","at":399,"chars":94},{"level":2,"title":"Remarks","slug":"remarks","at":493,"chars":829},{"level":2,"title":"Example","slug":"example","at":1322,"chars":849},{"level":2,"title":"Related information","slug":"related-information","at":2171,"chars":137}],"text":"> Version: _Available or changed with runtime version 1.0._\nCounts the number of records that are in the filters that are currently applied to the table referred to by the RecordRef.\n## Syntax\n```al\nNumber :=   RecordRef.Count()\n```\n> NOTE\n> This method can be invoked using property access syntax.\n## Parameters\nRecordRef\nType: recordref-data-type\nAn instance of the recordref-data-type data type.\n## Return Value\nNumber\nType: ../integer/integer-data-type\nThe number of records in the table.\n## Remarks\nThis method returns the number of records that meet the conditions of any filters associated with the records. If no filters are set, the method shows the total number of records in the table.\n> NOTE\n> The Count method does not lock the table before it retrieves the number of records in the table. This means that the method reads both uncommitted and committed data, which could cause the number of records that is returned to be inaccurate. To make sure that the count is accurate, use the recordref-locktable-method before you use the Count method.\nIn previous versions of Dynamics 365, the Count method ignored security filters and always returned the total number of records unless you called the SetPermissionFilter method to get a filtered count.\nThis method works just like the ../record/record-count-method.\n## Example\nThe following example opens table number 18 \\(Customer\\) as a RecordRef that is named MyRecordRef. The recordref-locktable-method locks the table. The Count method then retrieves the number of records in the table. The number of records is stored in the Count variable. The name of the table and the number of records in the table is displayed in a message box. The varTableNo variable can be used to open any table and get the number of records in that table by changing the value of the varTableNo variable.\n```al\nvar\n    MyRecordRef: RecordRef;\n    varTableNo: Integer;\n    Count: Integer;\n    Text000: Label 'The number of records in the %1 table is: %2.';\nbegin\n    varTableNo := 18;\n    MyRecordRef.Open(varTableNo);\n    MyRecordRef.LockTable;\n    Count := MyRecordRef.Count;\n    Message(Text000, MyRecordRef.Name, Count);\nend;\n```\n## Related information\nrecordref-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}