1

Although exporting using the data loader, Why does the result of SOQL query do not become the order of the selected fields?

Example.
Data Loader
Step 3: Edit your query
SELECT
Id,
Name,
xxx1,
xxx2
FROM
Account

execute

result

Id, Name, xxx2, xxx1 ← It is different from the order specified by select

If the data loader can not do the order in which the items are specified, can you see the regularity?

  • Not really sure why it does that, but that begs the question...why does the order of returned fields matter? – Derek F May 27 '18 at 13:47
  • 4
  • 1
    I believe, by default, the Data Loader reorders the results based on the schema definition of the object (so Id is always first, Name is always second, other standard fields follow, then custom fields). SOQL inherently doesn't change the order of the fields in the query that I've ever seen (also, not mentioned in the documentation). Try your same query in the Developer Console (Your Name > Developer Console > Query) to see if you get the fields back in the selected order. – sfdcfox May 27 '18 at 14:12
1

My Java is a bit rusty, but I think the answer can be found in SOQLMapper.java and the parent class Mapper.java.

SOQLMapper.java:

public SOQLMapper(PartnerClient client, Collection<String> columnNames, Field[] fields, String mappingFileName)
        throws MappingInitializationException {
    super(client, columnNames, fields, mappingFileName);
}

Mapper.java...

protected Mapper(PartnerClient client, Collection<String> columnNames, Field[] fields, String mappingFileName)
        throws MappingInitializationException {
    \\...
    Set<String> daoColumns = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    if (columnNames != null) daoColumns.addAll(columnNames);
    this.daoColumns = new CaseInsensitiveSet(Collections.unmodifiableSet(daoColumns));
    putPropertyFileMappings(mappingFileName);
    \\...
}

It appears the selected columns make there way into an unordered TreeSet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy