bcquality/community/knowledge/performance/load-only-primary-key-fields-for-reference-work.md
Jesper Schulz-Wedde 9a4198eb28 Add [all] sentinel to bc-version; apply to version-agnostic knowledge
Most of the corpus — FindSet/SetLoadFields/CalcFields patterns, permission
sets, SingleInstance codeunits, DataClassification, IsolatedStorage,
transaction scope, SecretText — describes BC platform behaviour that is
identical across supported versions. The seed [26..28] range on every
file implied a version-specificity the content does not actually have,
and there was no way to express "applies to every version" in the
schema the way [w1] and [all] already do for countries and
application-area.

Extend the v1 schema with a universal sentinel for bc-version, parallel
to the sentinels already defined for the other dimensions:

  bc-version: [all]         # applies to every BC version

[all] is mutually exclusive with explicit versions. Range shorthand
([26..28]) and explicit lists ([26, 27, 28]) continue to work for files
genuinely tied to a version-gated API or deprecation.

Update read.md (field definition, matching semantics, partial-context
rule), write.md (default to [all], use ranges only with a concrete
reason), README.md (frontmatter example), and the CI validator. All
forty existing knowledge files and the three action skills convert to
[all]; none of the current content is version-gated. Validator passes.
2026-04-23 16:00:03 +02:00

1.6 KiB

bc-version domain keywords technologies countries application-area
all
performance
setloadfields
primary-key
reference
existence-check
memory
al
w1
all

Load only primary key fields for reference work

Seed article. Ported from BC Code Intelligence to seed the community corpus. Community contributors are invited to expand or refine.

Description

Work that uses a record only for its identity — passing it to another procedure that will re-fetch what it needs, queueing a key for later processing, running existence checks, or building a reference collection — does not need non-key payload fields. SetLoadFields with only the primary key fields loads the minimum that preserves record identity while skipping everything else. On wide tables with large text, BLOB, or media fields the difference in memory and transfer is substantial.

Best Practice

When the iterating code's body touches only primary key fields (or passes the record to another procedure that will apply its own SetLoadFields), declare SetLoadFields with just the primary key fields before applying filters and calling FindSet. Callers downstream that need more fields issue their own Get or extend the load explicitly.

See sample: load-only-primary-key-fields-for-reference-work.good.al.

Anti Pattern

Using the default full-record load in loops whose body only reads the primary key, or forwards the record to another codeunit that immediately re-queries. The non-key payload is fetched across the wire and held in memory for the duration of the loop, then discarded unread.

See sample: load-only-primary-key-fields-for-reference-work.bad.al.