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
Rajeevls88Rajeevls88 

Ant tool usage

How can i use the ant tool to extract reports and dashboards from SFDC. Ant is installed on my system

Navatar_DbSupNavatar_DbSup

Hi,


Using Ant to retrieve metadata of Salesforce components


I was using Eclipse to download the metadata for all reports, and then using a "Search all files" to run a search on the field's API name. But downloading the metadata is a really time-consuming process. Ant can accomplish the same thing in a matter of split seconds!

Here's how to download all your Salesforce metadata (including emails, reports, dashboards, etc) using the Salesforce ant distribution package from Salesforce and java ant. (Note that I'm installing this on Windows 7)

Installation
Step 1: Download Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html. Install anywhere.

IMPORTANT NOTE: JDK 7 caused a problem in my Eclipse IDE at work, but it was fine on my home computer. Just FYI.

Step 2: Download Ant: http://ant.apache.org/bindownload.cgi. Extract.

Step 3: Download the Salesforce ant distribution package from Salesforce: Setup | Develop | Tools, and then click Force.com Migration Tool. Extract.

From the distribution zip file, copy ant-salesforce.jar into your Ant installation /lib/ directory.

Step 4: Set environment variables. Instructions here -- http://ant.apache.org/manual/install.html#setup

(Windows 7) Here are the environment variables to set:

  1. Add both Java and Ant bin directory to your path -- no spaces in the path!
  2. Set the ANT_HOME environment variable to the directory where you installed Ant.
  3. Optionally, set the JAVA_HOME environment variable



To view or change environment variables:

  1. Right-click My Computer, and then click Properties.
  2. Click the "Advanced system settings" option.
  3. Click the "Advanced" tab
  4. Click Environment variables.


Step 5: Open command prompt as administrator (right-click, select "Run as administrator"). Test your installation by typing in "ant -version". You should see something like this:

 


Retrieve all Report folders
So if you look at the Metadata API documentation, you'll soon realize that you can do a grab * to retrieve all data for a particular component, such as ApexClass or CustomApplication. HOWEVER, you'll also realize that not all components are wildcard-able, including CustomObjects and Reports. You'll have to list all folders to retrieve the data under them. Therefore, since the goal of this tutorial is how to retrieve all metadata for reports, here's how to retrieve the list of all report folders.

Step 1: Create a new project in Eclipse with the login credentials of the salesforce environment that you wish to search. Finish that process.

Step 2: Once that's done, right-click on your project, select Force.com > "Add/Remove Metadata Components".

Step 3: Select all metadata checkboxes. Click the OK button.

Step 4: This step is very important! Click "Apply" but DO NOT DOWNLOAD CONTENTS! You can do this by clicking the "No" button on the next two popup windows that asks if you'd like to refresh your project and download additional contents.

Step 5: When that's done, right-click on your src folder, select "Properties", copy the Location.

Step 6: Open that location in your file explorer, copy the file "package.xml".


Retrieving Metadata
Back to our Ant installation. In our Salesforce ant installation directory, looking at build.xml, the target that we are interested in is "retrieveUnpackaged".

What I did was to make a copy of the "sample" directory to work with. This is important, because, as it turned out, there was an error in the Salesforce Metadata API documentation, and it helped to have a reliable source file to compare against. You may want to have a copy for each Salesforce environment that you're working with. But for the sake of this tutorial, I'll assume you're working right off the sample directory that came with the download.

Step 1: Copy package.xml into <salesforce ant directory>/sample/unpackaged/package.xml. You can create the directory if it's missing.

Step 2: Under <salesforce ant directory>/sample/, edit build.properties to insert your salesforce login credentials. Remember to insert your security token after the password if you're working outside of your Salesforce's IP range.

Step 3: In the same folder, there is a build.xml. Look for <target name="retrieveUnpackaged">. It should look like this:

<target name="retrieveUnpackaged">

  <mkdir dir="retrieveUnpackaged"/>

  <!-- Retrieve the contents into another directory -->

  <sf:retrieve username="${sf.username}"

               password="${sf.password}"

               serverurl="${sf.serverurl}"

               retrieveTarget="retrieveUnpackaged"

               unpackaged="unpackaged/package.xml"/>

</target>

Step 4: In command prompt, cd to <salesforce ant directory>/sample/ and run "ant retrieveUnpackaged".

Here's a screenshot of a successful retrieval:

 

Error: If you're getting this error, you may have to set the proxy in build.xml:

 

<project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file="build.properties"/>

    <setproxy proxyhost="prxoy server URL" proxyport="port num"/>

    <property environment="env"/>

...



Source:
jkraybill:
http://stackoverflow.com/questions/6793458/how-to-download-all-salesforce-com-report-metadata-for-extremely-large-orgs

Force.com Migration Tool Guide:
http://wiki.developerforce.com/index.php/Migration_Tool_Guide

Force.com Migration Tool Installation Guide:
http://www.salesforce.com/us/developer/docs/daas/index_Left.htm#StartTopic=Content/forcemigrationtool_install.htm

Force.com Metadata API Guide:
http://www.salesforce.com/us/developer/docs/api_meta/api_meta.pdf

Apache Ant Installation Guide:
http://ant.apache.org/manual/install.html#setup

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

madhunayaki2000@gmail.commadhunayaki2000@gmail.com

hi

What is is the development environmet URL.

how to login.

Thanks.

Madhu