+ Start a Discussion
Vijay sidaraddiVijay sidaraddi 

How to write a batch schedule to get CSV file from FTP location in salessforce

Hi frineds,

How to write a batch process to pull records from a csv file which is kept in an FTP location. We will need this for PO/ materials integration Can someone help me on this.

 

Thanks

Vijaykumar S

NagendraNagendra (Salesforce Developers) 
Hi Vijay,

Generating a CSV file for export via Apex is pretty straight forward [1].  The problem is going to be that you cannot directly interact with an FTP system via Apex.  I would suggest that you try to setup a web application that you can do a POST call to and that saves your CSV file to disk.  I would also recommend reviewing the asynchronous apex [2] and integration [3] trailheads.
  1. http://www.salesforcetutorial.com/how-to-export-data-in-csv-by-using-apex-code/
  2. https://developer.salesforce.com/trailhead/module/asynchronous_apex
  3. https://developer.salesforce.com/trailhead/module/apex_integration_services

For more information check here
https://developer.salesforce.com/forums/?id=906F00000008n0zIAA

Please close this thread by marking it as solved if it helps.

Best Regards,
Nagendra.P
Vijay sidaraddiVijay sidaraddi
hi Team,

Im going to do this by using CLI but i got below error someone suggest me 
my object Name : purchageorder

C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\bin>process "C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test" PurchageorderInsert
2016-09-26 15:34:18,822 INFO  [main] controller.Controller initLog (Controller.java:389) - Using built-in logging configuration, no log-conf.xml in C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\bin\log-conf.xml
2016-09-26 15:34:18,822 INFO  [main] controller.Controller initLog (Controller.java:391) - The log has been initialized
2016-09-26 15:34:18,839 INFO  [main] process.ProcessConfig getBeanFactory (ProcessConfig.java:104) - Loading process configuration from config file: C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\process-conf.xml
2016-09-26 15:34:18,908 INFO  [main] support.AbstractApplicationContext prepareRefresh (AbstractApplicationContext.java:495) - Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1cfe4b2: startup date [Mon Sep 26 15:34:18 IST 2016]; root of context hierarchy
2016-09-26 15:34:18,939 INFO  [main] xml.XmlBeanDefinitionReader loadBeanDefinitions (XmlBeanDefinitionReader.java:315) - Loading XML bean definitions from file [C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\process-conf.xml]
2016-09-26 15:34:18,986 INFO  [main] support.DefaultListableBeanFactory preInstantiateSingletons (DefaultListableBeanFactory.java:557) - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@136f0f5: defining beans [purchageorderUpsertProcess]; root of factory hierarchy
2016-09-26 15:34:19,002 ERROR [main] process.ProcessConfig getProcessInstance (ProcessConfig.java:96) - Error loading process: PurchageorderInsert configuration from config file: C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\process-conf.xml
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'PurchageorderInsert' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
        at com.salesforce.dataloader.process.ProcessConfig.getProcessInstance(ProcessConfig.java:93)
        at com.salesforce.dataloader.process.ProcessRunner.getInstance(ProcessRunner.java:287)
        at com.salesforce.dataloader.process.ProcessRunner.getInstance(ProcessRunner.java:273)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.java:246)
2016-09-26 15:34:19,017 FATAL [main] process.ProcessRunner topLevelError (ProcessRunner.java:238) - Failed to create process
com.salesforce.dataloader.exception.ProcessInitializationException: Error loading process: PurchageorderInsert configuration from config file: C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\process-conf.xml
        at com.salesforce.dataloader.process.ProcessConfig.getProcessInstance(ProcessConfig.java:97)
        at com.salesforce.dataloader.process.ProcessRunner.getInstance(ProcessRunner.java:287)
        at com.salesforce.dataloader.process.ProcessRunner.getInstance(ProcessRunner.java:273)
        at com.salesforce.dataloader.process.ProcessRunner.main(ProcessRunner.java:246)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'PurchageorderInsert' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
        at com.salesforce.dataloader.process.ProcessConfig.getProcessInstance(ProcessConfig.java:93)

 
Vijay sidaraddiVijay sidaraddi
process-conf.xml file having 

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="purchageorderUpsertProcess" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
        <description>purcahgeorder gets the order record from the CSV file
        and inserts it into Salesforce.</description>
        <property name="name" value="purchageorderUpsert"/>
        <property name="configOverrideMap">
            <map>
    <entry key="sfdc.debugMessages" value="True"/>
    <entry key="sfdc.debugMessagesFile" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\logs\purchageorder.log"/>
    <entry key="sfdc.endpoint" value="https://login.salesforce.com"/>
    <entry key="sfdc.username" value="sanvitha2503@gmail.com"/>
    <!--Password below has been encrypted using key file,
                therefore, it will not work without the key setting:
                process.encryptionKeyFile.
                The password is not a valid encrypted value,
                please generate the real value using the encrypt.bat utility -->
<entry key="sfdc.password" value="78fe7daf016bd1af1ff6f84f0f2d7a391af3d4c8efea221528b1aa65c96bc811104d5383549712c359d5437383d1c2653e1df2acf1eec4f3abcb8efd234cc7418e5f33c6600df4856ff5b4ce102061ef6ed0a025b1f5fbefe7da29145bf05d4fb2fd62c18a1ced17"/>
                <entry key="process.encryptionKeyFile" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\key.txt"/>
                <entry key="sfdc.timeoutSecs" value="600"/>
                <entry key="sfdc.loadBatchSize" value="200"/>
                <entry key="sfdc.externalIdField" value="PO_Number__c"/>
                <entry key="sfdc.entity" value="Purchageorder"/>
                <entry key="process.operation" value="upsert"/>
                <entry key="process.mappingFile" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\test\PurchageorderMap.sdl"/>
                <entry key="dataAccess.name" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\Process\PurchageorderExtract.csv"/>
                <entry key="process.outputSuccess" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\logs\PurchageorderUpsert_success.csv"/>
                <entry key="process.outputError" value="C:\Users\vijaykumar.sidaraddi\AppData\Local\salesforce.com\Data Loader\logs\PurchageorderUpsert_error.csv"/>
                <entry key="dataAccess.type" value="csvRead"/>
                <entry key="process.initialLastRunDate" value="2005-12-01T00:00:00.000-0800"/>
            </map>
        </property>
    </bean>
</beans>

suggest me where im wrong in this 
thanks
vijaykumar.S