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
Aditi Singh 41Aditi Singh 41 

SOQL with subquery is optimum or 2 SOQL queries.

I am writing a trigger to update related list records. Can anyone guide me what is better approach.
  1. I should write a single SOQL query which will query all new inserted records(need lookup fields data) and the related list records of that account, in a single query.
  2. Or I should make two separate queries in trigger get records and related list records.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Aditi,

I would suggest the first option because of the time it takes to assign to the list and then quering based on the some collection and again assign to the list which takes more time than the first scenerio.

If this solution helps, Please mark it as best answer.

Thanks,