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
avtopi786avtopi786 

Data Loader Batch Query

Hi,

 

I would like to use dynamic query from Data Loader batch mode to extract only data that is changed since last run. Is there any way to achieve that by configuring in process-conf.xml file ?

 

Here is example:

Select Id, Name FROM Account where lastModifiedDate > @process.lastRunDate@

 

I found couple of posts that recommend using @process.lastRunDate@, but it does not work in my case.

 

Any help would be appreciated.

 

thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

you would have replacement tokens in place of the actual dates in the (template) process-config.xml. you would schedule it to run via windows schedules, which invokes a bat file.

the bat file first invokes the java class, which operates on the template of the process-conf, replaces the date values (using simple string replace), and records the date values into a file. it then writes the output to a configured dir.

next the bat file invokes dataloader command line, passing the path of the config dir to which the process-conf has been written.

so yes, the java class would run before the dataloader execution.

All Answers

Ritesh AswaneyRitesh Aswaney

You will need to pass your process-conf file through a replacement routine, to  replace the date token with the date of your last run (which would prolly have to be written to a text file as a marker) . this should be possible using a shell script (grep / awk), if unix is your runtime environment.

 

I'm not sure about the text replacement capability of dos batch files, but a simple java class could do this for you on windows and / or unix.

 

 

avtopi786avtopi786

@Ritesh

 

Can you briefly describe how you would achieve that with simple java class. I assume that you would first run java class that will update process-conf file with last run date and then batch data loader.

 

thanks!

Ritesh AswaneyRitesh Aswaney

you would have replacement tokens in place of the actual dates in the (template) process-config.xml. you would schedule it to run via windows schedules, which invokes a bat file.

the bat file first invokes the java class, which operates on the template of the process-conf, replaces the date values (using simple string replace), and records the date values into a file. it then writes the output to a configured dir.

next the bat file invokes dataloader command line, passing the path of the config dir to which the process-conf has been written.

so yes, the java class would run before the dataloader execution.

This was selected as the best answer
Nidhi SharmaNidhi Sharma

Ritesh,Can you please post the sample java class for that?

 

Rahul Jain.ax1619Rahul Jain.ax1619

import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.lang.*;

public class <CLASS_NAME>  {
    public static void main(String[] args) {
        try {
            Properties prop = new Properties();

            String propFileName = lastRunOutputDir+"/<PROPERTY_FILE_NAME>";
            
            Date today = new Date();
            SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");
            String currentTime = dt.format(today) + "T00:00:00.000Z";
            lastRunTime = currentTime;
                File fileCheck = new File(propFileName);
                     if(fileCheck.exists()){
                        prop.load(new FileInputStream(propFileName[i]));
                         lastRunTime = prop.getProperty("process.lastRunDate");
    
            try
            {
                BufferedReader br = new BufferedReader(new FileReader("conf/process-conf-template.xml"));
                BufferedWriter out = new BufferedWriter(new FileWriter("conf/process-conf.xml"));
                String inStr = new String();
                String outStr = new String();
                int i=0;
                while((inStr = br.readLine()) != null) {
                    
                    if(inStr.indexOf("<Replacement Token>")>=0){
                        outStr = inStr.replace("<Replacement Token>", lastRunTime[i]);
                        i++;
                    }else {
                        outStr = inStr;
                    }
                    
                    out.write(outStr);
                    out.write("\n");
                }
                br.close();            
                out.close();
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Nidhi SharmaNidhi Sharma

Thanks Rahul.