Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:42:42+00:00 2026-06-04T19:42:42+00:00

Setup: Say I have five Contact sObjects that I create and apex. When you

  • 0

Setup:

Say I have five Contact sObjects that I create and apex. When you insert a contact one at a time, you have x soql queries by way of triggers and stuff it uses.

Questions:

  1. So if you insert each contact one at a time in your code you get 5x soql queries (right?).

  2. Now say you put those 5 guys into an array and insert the array using one insert. How many soql queries are there?

  3. In regards to 2, if It’s 5x, why do we bother? So we can decrease the number of DML’s by 4?

Thanks,

The semi-new guy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:42:44+00:00Added an answer on June 4, 2026 at 7:42 pm

    A given block of code and all of the synchronous apex code that executes because of it is evaluated in a single execution context, which means that it has a single set of governor limits. In the example that you give, suppose that your Contact trigger makes 3 SOQL queries and one DML statement. If you inserted each contact separately, then you would use 5 DML statements (one for each Contact insert) + 1 DML statement for each trigger, and 3 * 5 SOQL statements for each trigger, leading to a total of 15 SOQL statements and 10 DML statements for your code. However, if you inserted them as a list, then all five records would be sent as a list to your trigger (1 DML statement) which would then execute its 3 SOQL queries and 1 DML statement once, for a total of 3 SOQL queries and 2 DML statements.

    The key here is to design your triggers (and most of your other code) so that the number of queries and statements is not dependent on the number of records you are dealing with. Salesforce provides a brief guide for that here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bulk_idioms.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following setup. Class, say, Car that has a CarPart (belongsTo=[car:Car]). When
Let's say I have this blob of code that's made to be one long-running
Lets say we have this scenario a setup that deploys a .net com dll
So let's say I have the following setup in Google Reader Folder One Engadget
Here's the setup. Say I have some action filter that needs an instance of
Let's say I have a setup like this: public ActionResult Create(int someUnrelatedNumber) { ...
Let's say you have the following setup. You have a server with the basepath
I have a mongoose setup which involves an embedded-schema, lets say: A Blogpost with
Lets say I have model inheritance set up in the way defined below. class
Let's say that I setup my own cloud using the open source cloud foundry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.