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
Tanner RussellTanner Russell 

Make SFDC Extraction Query Dynamic

I have the task where I need to make all of the data export dynamic and automated I have the automation part all handled the issue Im running into is on the line
<entry key="sfdc.extractionSOQL" value="Select Id, name FROM Account"/>
I need this to cover all of the fields on the object and if a new field was added that day it will need to be added to the query and included..

basically I just need a way to change all my extraction queries to select * from account etc for each object and it will be done and working any ideas? does sfdc support the select * syntax or a variation?
Karthikeyan Rajendran 14Karthikeyan Rajendran 14
Hi Tanner Russell

      There is no explicit way (lik Select *) to achieve what you want but it can be done in the following way

      Schema.getGlobalDescribe.get('Account').getDescribe().fields.getMap() - gives you all the API names (field name) available in the object.
     
String selectFields = '';
Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe.get('Account').getDescribe().fields.getMap();
      for(String key : fieldMap.keySet()){
           selectFields = selectFields + fieldMap.get(key) + ',' ;
      }
      
      selectFields = selectFields.substring(0,selectFields.length() - 1);
I hope the above solution is helpful for you. Let me know it it does.

Regards
Karthik
Tanner RussellTanner Russell
How can I incorporate the apex into the data loader xml process config file?
Karthikeyan Rajendran 14Karthikeyan Rajendran 14
Hi Tanner Russel

    In the process-conf.xml file have you tried using Select * from Account in sfdc.extractionSOQL.  When it comes to extracting data using data loader CLI it seems you can use * to fetch all the objects. if you are getting error then you have to use the above method to fetch all the fields and use it in the xml.

Regards
Karthik
Tanner RussellTanner Russell
Hey do you know what version of dataloader cli that works on? Im using an older version and it is not working if its just a version issue than I will upgrade.
Tanner RussellTanner Russell
I updated and select * still doesnt work but I built out an endpoint and used rest to pull a metadata query like you mentioned above, and taged them all in an xml file such as <root><account>select id from account</account><root> Im pretty rusty with the xml stuff what is the way to embed the soql query xml node of account into the dataloader config? if you know