Select Only Fields You Need

GlideRecord pulls every field by default. For large tables or tight loops, use setFieldsNeeded() or GlideAggregate when counting. Saves memory and transit time.

Use addEncodedQuery for Complex Conditions

Complex where-clauses compose better with encoded queries (the format used in list URL filters). Reusable, shareable, and easier to test than chained addQuery() calls.

Chunk Large Queries

Never retrieve millions of rows in one shot. Use setLimit() + pagination, or walk with addQuery on sys_id > lastSysId. Batch sizes of 1000–5000 are a good default.

GlideAggregate for Counting

gr.getRowCount() fetches all rows and counts in JS. Wrong approach on a big table. GlideAggregate pushes the count to the database. Always use it for aggregates.

Never Query in a Loop

Nested GlideRecord queries inside iteration over a parent result set is the classic N+1 trap. Collect IDs first, then one query with sys_id IN (list).

Share