Boosting Performance in Business Central with SetLoadFields() and related features
Boosting Performance in Business Central with SetLoadFields() and related features
When working with large datasets in Dynamics 365 Business Central, performance optimization is critical — especially when retrieving records that include many fields. Microsoft has introduced a handy feature called SetLoadFields() to help developers improve data access performance by explicitly specifying which fields to load from the database.
What is SetLoadFields()?
The SetLoadFields() method allows you to define exactly which fields should be loaded when fetching records from a table. This is a performance-enhancing alternative to loading all fields by default.
Example:
Customer.SetLoadFields("No.", "Name");
if Customer.Get('10000') then
Message('Customer name: %1', Customer.Name);
In this snippet, only the No. and Name fields are loaded. Any attempt to access a field not listed in SetLoadFields() will result in a runtime error — ensuring you load only what's necessary and nothing more.
When to Use SetLoadFields()
When working with large tables and you only need a few fields
To reduce memory consumption
To improve performance in read-heavy operations like reports, integrations, or APIs
Tip
Combine SetLoadFields() with FindFirst(), FindSet(), or Get() for blazing-fast reads — just be careful to avoid accessing unlisted fields, or you'll hit an error.
Related Field handling feature
1. SetAutoCalcFields
This method is used to automatically calculate FlowFields when records are retrieved.
Customer.SetAutoCalcFields("Balance");
Useful when you need FlowField values without calling CalcFields explicitly.
2. CalcFields
Manually triggers the calculation of one or more FlowFields.
Customer.CalcFields("Balance");
Use this when you're not using SetAutoCalcFields, but still need FlowField values.
3. SetRange / SetFilter
These are classic filtering methods used before data retrieval, which can work hand-in-hand with SetLoadFields.
Customer.SetRange("Country/Region Code", 'US');
4. Calculate values only for visible FlowFields
By default in BCv26 and the previous version, FlowFields are calculated even if they’re not visible on a page. This can slow things down unnecessarily. However, now in BCv26, you can enable the “Calculate only visible FlowFields” feature in the Feature Management page.
Once it’s on, Business Central will only calculate FlowFields that are actually visible, boosting performance.
That's it for this one.
Comments
Post a Comment