I have a use case where I need to insert data in salesforce which is being exported from an external system. This data is split over multiple rows, and I need to get those multiple rows into the sobjects. What I do is just insert everything in separate records in salesforce, and based on those separate records I construct records of another type with Apex.

However, Am I sure that records inserted via the dataloader, are inserted in the same order in Salesforce. Say I add a custom field of type Autonumber, can I sort on that field, and be sure that the results I get are in the same order as the results in the upload file.

I have a feeling that the order of the inserted records can possibly be different from the order in an upload file because Salesforce is a multi-tennant environment.

  • If you must depend on the order, make your field a text field to begin with, and explicitly load the values you expect in the order you want, then later convert the field to an auto-number field.
    – sfdcfox
    Jun 10, 2014 at 16:25
  • the problem is, I don't have anything in my export file that defines an order or binds values that belong together in the same group (apart from the actual order), and I want to refrain from altering my export file in a separate script or program
    – pjcarly
    Jun 11, 2014 at 7:51
  • Make sure the Bulk API option is disabled, and you'll generally get the results you want. You can also set the "batch size" to 1, but expect it to take a very long time to load the data as opposed to using the nominal 200 batch size.
    – sfdcfox
    Jun 11, 2014 at 16:47

2 Answers 2


If you're loading data with the bulk API, then the rows may be inserted in a different order to what they appear in the original CSV. The dataloader uses the Bulk API by default, although you can turn this off. If you turn off the bulk API,then the rows will be inserted in the order in the CSV, assuming there are no errors, if there are errors, and/or apex triggers and/or workflow, then these can all end up messing with the insertion order. Also other users can be inserting data into the same object concurrently with your dataload [unless you have a locked down security model to prevent this].

Its not really clear how the insertion order helps you, but unless you can lock down to a very specific setup, you can't rely on it.

  • "uses the Bulk API by default"-- is this new? Every time I've installed it, it's been defaulted off, although admittedly it's been a few months.
    – sfdcfox
    Jun 10, 2014 at 16:22
  • Its the default in LexiLoader, but you're right it might not be the default for the Windows version.
    – superfell
    Jun 10, 2014 at 18:14
  • what API is being used when you're not using the bulk api? * I will be the only one inserting records, and there are no validation rules, no triggers, just plain 1-on-1 insert, so I can more or less assume there won't be any errors. I assume I must disable the bulk api in the dataloader I use?
    – pjcarly
    Jun 11, 2014 at 7:39

I would never assume that records are in an expected order. Often, it appears like records are in a particular order, but there is no guarantee they will be unless you explicitly sort it yourself via code. As a rule of thumb, I always assume there is no exact order and account for it no matter what I'm doing. Unfortunately, I don't have the time to find an exact documentation that agrees with what I'm saying.

  • Sort of. Synchronous API calls appear to always leave the records in order, although like you, I don't have any documentation on that. Asynchronous calls could re-order the data, as Simon Fell answered.
    – sfdcfox
    Jun 10, 2014 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .