Steps I followed to get Enterpise.jar
>>First and foremost, I took the Enterprise wsdl from Salesforce and downloaded "force-wsc-40.0.0.jar","ST4-4.0.8.jar",antlr-runtime-3.5.2.jar, js.jar(Rhino) and then took tools.jar from JDK.
>> Kept all these files in one single folder(alljars).
>> Given the path of this folder in the cmd(C:\Users\thimma.v\Desktop\alljars).
>> Then then adjusted JAVA_HOME, CLASSPATH and Path(please exact path which I had set in my environment variables)
path: .;%JAVA_HOME%
ClASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\jre\lib;%JAVA_HOME%\jre\lib\rt.jar;.\force-wsc-40.0.0.jar;.\enterprise.jar;
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_241\bin
C:\Users\thimma.v\Desktop\alljars>java -classpath ST4-4.0.8.jar;tools.jar;js.jar;antlr-runtime-3.5.2.jar;force-wsc-40.0.0.jar com.sforce.ws.tools.wsdlc ent.wsdl.xml enterprise.jar
[WSC][wsdlc.main:71]Generating Java files from schema ...
[WSC][wsdlc.main:71]Generated 990 java files.
[WSC][wsdlc.main:71]Compiling to target 1.6...
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
[WSC][wsdlc.main:71]Compiled 994 java files.
[WSC][wsdlc.main:71]Generating jar file ... enterprise.jar
[WSC][wsdlc.main:71]Generated jar file enterprise.jar
>> Now I received generated Enterprise.jar.
>> Add Below Jars in the Eclipse.
force-wsc-40.0.0.jar(retrieved from Maven repository) and enterprise.jar(retrieved with the below cmd)
java -classpath ST4-4.0.8.jar;tools.jar;js.jar;antlr-runtime-3.5.2.jar;force-wsc-40.0.0.jar com.sforce.ws.tools.wsdlc ent.wsdl.xml enterprise.jar
>> Now run below code to get session ID and do further operations.
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
/*
* This class exercises the following functionality of the Web Services API
* using the enterprise.wsdl:
* - Login
* - Query
* - Update
*/
public class QueryAndUpdateaccountApp {
static final String USERNAME = "David@701.com";
static final String PASSWORD = "xxxxxxx";
static final String TOKEN = "AlDF5HNLniEjYxtvwuNFSheqp";
// the variable that will contain the connection that will be used to execute all
// SalesForce Web Services API.
static EnterpriseConnection connection;
// class constructor
public QueryAndUpdateaccountApp() {
// upon instantiation invoke process to perform the application logic
doWork();
}
// this is the entry point into the application
public static void main(String[] args) {
// create a new instance of the class to begin processing
new QueryAndUpdateaccountApp();
}
// this method comprises the bulk of the application logic
private void doWork() {
//TODO (Exercise 4-2): Set doQuery to true.
boolean doQuery = true;
//TODO (Exercise 4-3): Set doUpdate to true.
boolean doUpdate = true;
if (doLogin() && doQuery) {
// perform a sample query and output account information
Account account = doaccountQuery();
// if a record was returned, proceed with update
if (account != null && doUpdate) {
// update account
doaccountUpdate(account);
}
}
}
// this function encapsulates the logic necessary to login to salesforce.com
private boolean doLogin() {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
//append token to password if needed.
config.setPassword(PASSWORD + TOKEN);
//config.setTraceMessage(true);
//If using a proxy to get through a firewall, uncomment the following code and set appropriate values.
//config.setProxy("proxyServer.corp.myCorp.com",8080);
//config.setNtlmDomain("NtlmDom");
//config.setProxyUsername("proxyUserName");
//config.setProxyPassword("***");
try {
connection = Connector.newConnection(config);
// display some current settings
System.out.println("Auth EndPoint: " + config.getAuthEndpoint());
System.out.println("Service EndPoint: " + config.getServiceEndpoint());
System.out.println("Username: " + config.getUsername());
System.out.println("SessionId: " + config.getSessionId());
System.out.println("Sforce service created.");
return true;
} catch (ConnectionException e1) {
e1.printStackTrace();
return false;
}
}
// this function encapsulates the logic necessary to query salesforce.com and
// output information about existing accounts
private Account doaccountQuery() {
// declare local vars
QueryResult qr = null; // create a variable to hold the query result
Account account = null; // create a variable to hold the return value
/***********************************************************************
* TODO - (Exercise 4-2): WRITE THE LOGIC NECESSARY TO QUERY AND RETURN A SINGLE account
* 1. Declare a string to hold the SOQL query which will retrieve the id, first name, last name of a single account
* 2. Using the connection obtained in the doLogin() method, execute the query and obtain the result
* 3. This will need to be wrapped in a try-catch block. Simply catch a generic Exception and print out the
* error message to the console.
***********************************************************************/
String query = "select id, Name, Phone from Account LIMIT 1"; // query for account data
// call the query saving the results in qr
try {
qr = connection.query(query);
} catch (Exception e) {
System.out.println("Error getting accounts " + e.getMessage());
}
/***********************************************************************
* TODO - (Exercise 4-2):
* 4. Using the query result, obtain the account record from the first element in the list of records
* 5. Print out account's first and last name to the console.
***********************************************************************/
// iterate over the results and output the returned information
if (qr != null && qr.getSize() > 0) {
SObject[] records = qr.getRecords();
if (records.length != 0) {
// get a handle on the retrieved account
account = (Account) records[0];
// output information about the account
System.out.println("Retrieved account: ");
System.out.println(account);
System.out.println(account.getId());
}
}
// return the account
return account;
}
// this function encapsulates the logic necessary to update a received account
// within salesforce.com and output the results
private void doaccountUpdate(Account account) {
// First we will create a account object array, all calls are batch ours is a single element batch
Account[] accounts = new Account[1];
/***********************************************************************
* TODO (Exercise 4-3) - WRITE THE LOGIC NECESSARY TO UPDATE THE PHONE AND MOBILE FOR THE RECIEVED account
*
* 6. Set the phone and mobile fields on the account object
* 7. Add the account object to the array of accounts
***********************************************************************/
// set the values for the account
account.setName("Dave");
account.setPhone("777-666-5555");
// add the account to the array of objects
accounts[0] = account;
// we are now ready to update the record
// create an array for the results
SaveResult[] saveResults = null;
/***********************************************************************
* TODO (Exercise 4-3)
* 8. Using the connection object initialized in the doLogin method, update the list of accounts and put the result in the saveResults array
* 9. This will need to be wrapped in a try-catch block. Simply catch a generic Exception and print out the error message to the console.
***********************************************************************/
try {
saveResults = connection.update(accounts);
} catch (Exception e) {
System.out.println("Error updating accounts " + e.getMessage());
}
// we will create a separate save result object for clarity
for (SaveResult saveResult : saveResults) {
// check to see if the first update was a success
if (saveResult.isSuccess())
// the id that we passed should be the one we get back.
{
System.out.println("Updated account with id: " + saveResult.getId());
} else {
// an error occurred on this record
System.out.println("Error: ");
Error error = saveResult.getErrors()[0];
System.out.println(error.getMessage());
}
}
}
}
====================Finally got below result=====================
Auth EndPoint: https://login.salesforce.com/services/Soap/c/47.0/0DF2v0000000ofJ
Service EndPoint: https://david701-dev-ed.my.salesforce.com/services/Soap/c/47.0/00D2v000001uTD6/0DF2v0000000ofJ
Username: David@701.com
SessionId: 00D2v000001uTD6!AQIAQB45BK1HOuJjUacxaDOcpUkyZje4GkwMGp3ra86PrkVThlgbCGaX1wpk45SMt3U3jLeTotQdplyrzzUXpwIfW_oEocuW
Sforce service created.
Retrieved account:
[Account [SObject fieldsToNull='{[0]}'
Id='0012v00002bjSF7AAM'
]
.
.
Phone='777-666-5555'
.
.
]
0012v00002bjSF7AAM
Updated account with id: 0012v00002bjSF7AAM
Note: If you have a trouble in getting enterprise.jar, you can use any jar which were retrieved by any developer earlier(to avoid the head of path setting and other errors related to it). You can ping me on thimma.salesforce@gmail.com in case if you want to get enterprise.jar for your POC.
>>First and foremost, I took the Enterprise wsdl from Salesforce and downloaded "force-wsc-40.0.0.jar","ST4-4.0.8.jar",antlr-runtime-3.5.2.jar, js.jar(Rhino) and then took tools.jar from JDK.
>> Kept all these files in one single folder(alljars).
>> Given the path of this folder in the cmd(C:\Users\thimma.v\Desktop\alljars).
>> Then then adjusted JAVA_HOME, CLASSPATH and Path(please exact path which I had set in my environment variables)
path: .;%JAVA_HOME%
ClASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\jre\lib;%JAVA_HOME%\jre\lib\rt.jar;.\force-wsc-40.0.0.jar;.\enterprise.jar;
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_241\bin
C:\Users\thimma.v\Desktop\alljars>java -classpath ST4-4.0.8.jar;tools.jar;js.jar;antlr-runtime-3.5.2.jar;force-wsc-40.0.0.jar com.sforce.ws.tools.wsdlc ent.wsdl.xml enterprise.jar
[WSC][wsdlc.main:71]Generating Java files from schema ...
[WSC][wsdlc.main:71]Generated 990 java files.
[WSC][wsdlc.main:71]Compiling to target 1.6...
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
[WSC][wsdlc.main:71]Compiled 994 java files.
[WSC][wsdlc.main:71]Generating jar file ... enterprise.jar
[WSC][wsdlc.main:71]Generated jar file enterprise.jar
>> Now I received generated Enterprise.jar.
>> Add Below Jars in the Eclipse.
force-wsc-40.0.0.jar(retrieved from Maven repository) and enterprise.jar(retrieved with the below cmd)
java -classpath ST4-4.0.8.jar;tools.jar;js.jar;antlr-runtime-3.5.2.jar;force-wsc-40.0.0.jar com.sforce.ws.tools.wsdlc ent.wsdl.xml enterprise.jar
>> Now run below code to get session ID and do further operations.
import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.SObject;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
/*
* This class exercises the following functionality of the Web Services API
* using the enterprise.wsdl:
* - Login
* - Query
* - Update
*/
public class QueryAndUpdateaccountApp {
static final String USERNAME = "David@701.com";
static final String PASSWORD = "xxxxxxx";
static final String TOKEN = "AlDF5HNLniEjYxtvwuNFSheqp";
// the variable that will contain the connection that will be used to execute all
// SalesForce Web Services API.
static EnterpriseConnection connection;
// class constructor
public QueryAndUpdateaccountApp() {
// upon instantiation invoke process to perform the application logic
doWork();
}
// this is the entry point into the application
public static void main(String[] args) {
// create a new instance of the class to begin processing
new QueryAndUpdateaccountApp();
}
// this method comprises the bulk of the application logic
private void doWork() {
//TODO (Exercise 4-2): Set doQuery to true.
boolean doQuery = true;
//TODO (Exercise 4-3): Set doUpdate to true.
boolean doUpdate = true;
if (doLogin() && doQuery) {
// perform a sample query and output account information
Account account = doaccountQuery();
// if a record was returned, proceed with update
if (account != null && doUpdate) {
// update account
doaccountUpdate(account);
}
}
}
// this function encapsulates the logic necessary to login to salesforce.com
private boolean doLogin() {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
//append token to password if needed.
config.setPassword(PASSWORD + TOKEN);
//config.setTraceMessage(true);
//If using a proxy to get through a firewall, uncomment the following code and set appropriate values.
//config.setProxy("proxyServer.corp.myCorp.com",8080);
//config.setNtlmDomain("NtlmDom");
//config.setProxyUsername("proxyUserName");
//config.setProxyPassword("***");
try {
connection = Connector.newConnection(config);
// display some current settings
System.out.println("Auth EndPoint: " + config.getAuthEndpoint());
System.out.println("Service EndPoint: " + config.getServiceEndpoint());
System.out.println("Username: " + config.getUsername());
System.out.println("SessionId: " + config.getSessionId());
System.out.println("Sforce service created.");
return true;
} catch (ConnectionException e1) {
e1.printStackTrace();
return false;
}
}
// this function encapsulates the logic necessary to query salesforce.com and
// output information about existing accounts
private Account doaccountQuery() {
// declare local vars
QueryResult qr = null; // create a variable to hold the query result
Account account = null; // create a variable to hold the return value
/***********************************************************************
* TODO - (Exercise 4-2): WRITE THE LOGIC NECESSARY TO QUERY AND RETURN A SINGLE account
* 1. Declare a string to hold the SOQL query which will retrieve the id, first name, last name of a single account
* 2. Using the connection obtained in the doLogin() method, execute the query and obtain the result
* 3. This will need to be wrapped in a try-catch block. Simply catch a generic Exception and print out the
* error message to the console.
***********************************************************************/
String query = "select id, Name, Phone from Account LIMIT 1"; // query for account data
// call the query saving the results in qr
try {
qr = connection.query(query);
} catch (Exception e) {
System.out.println("Error getting accounts " + e.getMessage());
}
/***********************************************************************
* TODO - (Exercise 4-2):
* 4. Using the query result, obtain the account record from the first element in the list of records
* 5. Print out account's first and last name to the console.
***********************************************************************/
// iterate over the results and output the returned information
if (qr != null && qr.getSize() > 0) {
SObject[] records = qr.getRecords();
if (records.length != 0) {
// get a handle on the retrieved account
account = (Account) records[0];
// output information about the account
System.out.println("Retrieved account: ");
System.out.println(account);
System.out.println(account.getId());
}
}
// return the account
return account;
}
// this function encapsulates the logic necessary to update a received account
// within salesforce.com and output the results
private void doaccountUpdate(Account account) {
// First we will create a account object array, all calls are batch ours is a single element batch
Account[] accounts = new Account[1];
/***********************************************************************
* TODO (Exercise 4-3) - WRITE THE LOGIC NECESSARY TO UPDATE THE PHONE AND MOBILE FOR THE RECIEVED account
*
* 6. Set the phone and mobile fields on the account object
* 7. Add the account object to the array of accounts
***********************************************************************/
// set the values for the account
account.setName("Dave");
account.setPhone("777-666-5555");
// add the account to the array of objects
accounts[0] = account;
// we are now ready to update the record
// create an array for the results
SaveResult[] saveResults = null;
/***********************************************************************
* TODO (Exercise 4-3)
* 8. Using the connection object initialized in the doLogin method, update the list of accounts and put the result in the saveResults array
* 9. This will need to be wrapped in a try-catch block. Simply catch a generic Exception and print out the error message to the console.
***********************************************************************/
try {
saveResults = connection.update(accounts);
} catch (Exception e) {
System.out.println("Error updating accounts " + e.getMessage());
}
// we will create a separate save result object for clarity
for (SaveResult saveResult : saveResults) {
// check to see if the first update was a success
if (saveResult.isSuccess())
// the id that we passed should be the one we get back.
{
System.out.println("Updated account with id: " + saveResult.getId());
} else {
// an error occurred on this record
System.out.println("Error: ");
Error error = saveResult.getErrors()[0];
System.out.println(error.getMessage());
}
}
}
}
====================Finally got below result=====================
Auth EndPoint: https://login.salesforce.com/services/Soap/c/47.0/0DF2v0000000ofJ
Service EndPoint: https://david701-dev-ed.my.salesforce.com/services/Soap/c/47.0/00D2v000001uTD6/0DF2v0000000ofJ
Username: David@701.com
SessionId: 00D2v000001uTD6!AQIAQB45BK1HOuJjUacxaDOcpUkyZje4GkwMGp3ra86PrkVThlgbCGaX1wpk45SMt3U3jLeTotQdplyrzzUXpwIfW_oEocuW
Sforce service created.
Retrieved account:
[Account [SObject fieldsToNull='{[0]}'
Id='0012v00002bjSF7AAM'
]
.
.
Phone='777-666-5555'
.
.
]
0012v00002bjSF7AAM
Updated account with id: 0012v00002bjSF7AAM
Note: If you have a trouble in getting enterprise.jar, you can use any jar which were retrieved by any developer earlier(to avoid the head of path setting and other errors related to it). You can ping me on thimma.salesforce@gmail.com in case if you want to get enterprise.jar for your POC.