function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Murthy vvrMurthy vvr 

How to access SObject records without writing SOQL in apex Triggers.

Hi, Is there any way to access existing records of SObject in isInsert block of a trigger. ???

 

          Trigger Trg_name on Sobj_Name(before insert) {

                if(Trigger.isInsert) {

                            //Here i need to access the existing records of Sobject without writing SOQL.

                }

          }

sfdcfoxsfdcfox
Are you referring to the records being inserted at that moment, or related records, or all records of a certain type? Your question is unclear.
Murthy vvrMurthy vvr

Thanks for the reply, Records being inserted can be accessed using Trigger.new, but  I need to access all records of certain type without writing SOQL.

sfdcfoxsfdcfox
Except for Custom Settings, you must always use SOQL or SOSL to retrieve records from a certain object. It is a developer's responsibility to determine how to build a query that will return just the necessary information.

There are too many checks in place to simply say that you would like to check against all records of one type, from the 200,000 script line limit, to the 50,000 query row limit, to the 12MB (or whatever it is these days) heap limit. Your job as a developer is to work within these constraints to use system resources effectively to complete the task.