+ 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.