Poorly written server-side scripts are the primary cause of instance performance degradation, slow form loads, and high database CPU usage. Learn how to write lightning-fast GlideRecord and GlideAggregate queries.
Rule 1: Always Limit Fields and Query Sets
// FAST: Using addEncodedQuery and setLimit
var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^priority=1");
gr.setLimit(50);
gr.query();
while (gr.next()) {
gs.info("P1 Incident: " + gr.getValue("number"));
}
Rule 2: Use GlideAggregate for Record Counts
Never use gr.getRowCount() on large tables! Use GlideAggregate to run SQL COUNT() directly in the database engine.