use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method createAndDeleteAnAccount.
private String createAndDeleteAnAccount(String accountName) {
String returnId = null;
SObject acct = new SObject();
acct.setType("Account");
String acctName = (accountName == null) ? "QueryAll Sample" : accountName;
try {
MessageElement nameField = newMessageElement("Name", acctName);
acct.set_any(new MessageElement[] { nameField });
// We are only creating one account so we can index the return array directly
SaveResult sr = binding.create(new SObject[] { acct })[0];
if (sr.isSuccess()) {
acct.setId(sr.getId());
// Ok, now we will delete that account
DeleteResult dr = binding.delete(new String[] { acct.getId() })[0];
if (!dr.isSuccess()) {
System.out.println("The web service would not let us delete the account: \n" + dr.getErrors(0).getMessage());
getUserInput("\nHit return to continue...");
} else {
returnId = acct.getId();
}
} else {
System.out.println("The web service would not let us create the account: \n" + sr.getErrors(0).getMessage());
getUserInput("\nHit return to continue...");
}
} catch (ApiFault e) {
System.out.println("Error creating test account: " + e.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException e) {
System.out.println("Error from the server on create test account: " + e.getMessage());
getUserInput("\nHit return to continue...");
} catch (Exception e) {
e.printStackTrace();
}
return returnId;
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method login.
/*
* login sample Prompts for username and password, set class variable binding resets the url for the binding and
* adds the session header to the binding class variable
*/
private boolean login() {
un = getUserInput("Enter user name: ");
if (un.length() == 0) {
return false;
}
pw = getUserInput("Enter password: ");
if (pw.length() == 0) {
return false;
}
// Provide feed back while we create the web service binding
System.out.println("Creating the binding to the web service...");
/*
* There are 2 ways to get the binding, one by passing a url to the getSoap() method of the
* SforceServiceLocator, the other by not passing a url. In the second case the binding will use the url
* contained in the wsdl file when the proxy was generated.
*/
try {
binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
} catch (ServiceException ex) {
System.out.println("ERROR: createing binding to soap service, error was: \n" + ex.getMessage());
System.out.print("Hit return to continue...");
return false;
}
// Time out after a minute
binding.setTimeout(60000);
// binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/services/Soap/u/8.0");
// Attempt the login giving the user feedback
System.out.println("LOGGING IN NOW....");
try {
loginResult = binding.login(un, pw);
} catch (LoginFault lf) {
System.out.println(lf.getExceptionMessage());
// lf.printStackTrace();
getUserInput("\nHit return to continue...");
return false;
} catch (ApiFault af) {
System.out.println(af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException re) {
System.out.println(re.getMessage());
re.printStackTrace();
getUserInput("\nHit return to continue...");
return false;
}
System.out.println("\nThe session id is: " + loginResult.getSessionId());
System.out.println("\nThe new server url is: " + loginResult.getServerUrl());
binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
// binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/services/Soap/u/8.0");
// Create a new session header object and set the session id to that
// returned by the login
SessionHeader sh = new SessionHeader();
sh.setSessionId(loginResult.getSessionId());
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);
loggedIn = true;
// call the getServerTimestamp method
getServerTimestampSample();
// call the getUserInfo method
getUserInfoSample();
return true;
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method createAccountSample.
private void createAccountSample() {
// call the login function to do so
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
SObject[] accs = new SObject[2];
for (int j = 0; j < accs.length; j++) {
MessageElement[] account = new MessageElement[14];
int index = 0;
if (accounts == null) {
account[index++] = newMessageElement("AccountNumber", "00000000");
} else {
account[index++] = newMessageElement("AccountNumber", "000000" + (accounts.length + 1));
}
account[index++] = newMessageElement("BillingCity", "Wichita");
account[index++] = newMessageElement("BillingCountry", "US");
account[index++] = newMessageElement("BillingState", "KA");
account[index++] = newMessageElement("BillingStreet", "4322 Haystack Boulevard");
account[index++] = newMessageElement("BillingPostalCode", "87901");
account[index++] = newMessageElement("Description", "World class hay makers.");
account[index++] = newMessageElement("Fax", "555.555.5555");
account[index++] = newMessageElement("Industry", "Farming");
account[index++] = newMessageElement("Name", "Golden Straw");
account[index++] = newMessageElement("NumberOfEmployees", new java.lang.Integer(40).toString());
account[index++] = newMessageElement("Ownership", "Privately Held");
account[index++] = newMessageElement("Phone", "666.666.6666");
account[index++] = newMessageElement("Website", "www.oz.com");
accs[j] = new SObject();
accs[j].set_any(account);
accs[j].setType("Account");
accs[j + 1] = accs[j];
j++;
}
// create the object(s) by sending the array to the web service
SaveResult[] sr = binding.create(accs);
for (int j = 0; j < sr.length; j++) {
if (sr[j].isSuccess()) {
System.out.println("An account was create with an id of: " + sr[j].getId());
// save the account ids in a class array
if (accounts == null) {
accounts = new String[] { sr[j].getId() };
} else {
String[] tempAccounts = null;
tempAccounts = new String[accounts.length + 1];
for (int i = 0; i < accounts.length; i++) {
tempAccounts[i] = accounts[i];
}
tempAccounts[accounts.length] = sr[j].getId();
accounts = tempAccounts;
}
} else {
// array and write them to the screen
for (int i = 0; i < sr[j].getErrors().length; i++) {
// get the next error
com.salesforce.soap.partner.Error err = sr[j].getErrors()[i];
System.out.println("Errors were found on item " + new Integer(j).toString());
System.out.println("Error code is: " + err.getStatusCode().toString());
System.out.println("Error message: " + err.getMessage());
}
}
}
getUserInput("\nHit return to continue...");
} catch (ApiFault af) {
System.out.println("\nFailed to create account, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("\nFailed to create account, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method setPasswordSample.
private void setPasswordSample() {
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
QueryResult qr = binding.query("select UserName, LastName, FirstName, Id from User");
if (qr.getSize() > 0) {
SObject[] users = qr.getRecords();
if (users != null) {
System.out.println("\nUser List: ");
for (int i = 0; i < users.length; i++) {
int printInd = i + 1;
SObject user = users[i];
System.out.println(printInd + ". " + user.get_any()[0].getValue() + " - " + user.get_any()[2].getValue() + " " + user.get_any()[1].getValue());
}
}
String idToReset = getUserInput("\nEnter user to set password for: ");
if (idToReset != null) {
int userIndex = new Integer(idToReset).intValue() - 1;
String newPassword = getUserInput("Enter the new password: ");
if (newPassword != null) {
String verify = getUserInput("Please verify that you want to reset the password for \n" + users[userIndex].get_any()[2] + " " + users[userIndex].get_any()[1] + "\n to " + newPassword + " by entering OK.");
if (verify.equals("OK")) {
SetPasswordResult setPasswordResult = binding.setPassword(users[userIndex].getId(), newPassword);
if (setPasswordResult != null) {
System.out.println("\nThe password for user " + users[userIndex].get_any()[2].getValue() + " " + users[userIndex].get_any()[1].getValue() + " has been reset to " + newPassword);
getUserInput("\nHit enter to continue...");
return;
}
}
}
}
}
} catch (ApiFault af) {
System.out.println("\nFailed to succesfully set password, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException ex) {
System.out.println("\nFailed to succesfully set password, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
getUserInput("No password was set....\nHit return to continue...");
}
use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.
the class PartnerSamples method resetPasswordSample.
private void resetPasswordSample() {
if (!loggedIn) {
if (!login()) {
return;
}
}
try {
QueryResult qr = binding.query("select UserName, LastName, FirstName, Id from User");
if (qr.getSize() > 0) {
SObject[] users = qr.getRecords();
if (users != null) {
System.out.println("\nUser List: ");
for (int i = 0; i < users.length; i++) {
int printInd = i + 1;
SObject user = users[i];
System.out.println(printInd + ". " + user.get_any()[0].getValue() + " - " + user.get_any()[2].getValue() + " " + user.get_any()[1].getValue());
}
}
String idToReset = getUserInput("\nEnter user to reset: ");
if (idToReset != null) {
int userIndex = new Integer(idToReset).intValue() - 1;
String verify = getUserInput("Please verify that you want to reset the password for \n" + users[userIndex].get_any()[2] + " " + users[userIndex].get_any()[1] + "\nby entering OK.");
if (verify.equals("OK")) {
ResetPasswordResult resetPasswordResult = binding.resetPassword(users[userIndex].getId());
if (resetPasswordResult != null) {
System.out.println("\nThe password for user " + users[userIndex].get_any()[2].getValue() + " " + users[userIndex].get_any()[1].getValue() + " has been reset to " + resetPasswordResult.getPassword());
getUserInput("\nHit enter to continue...");
return;
}
}
}
}
} catch (ApiFault af) {
System.out.println("\nFailed to succesfully reset password, error message was: \n" + af.getExceptionMessage());
getUserInput("\nHit return to continue...");
} catch (RemoteException ex) {
System.out.println("\nFailed to succesfully reset password, error message was: \n" + ex.getMessage());
getUserInput("\nHit return to continue...");
}
getUserInput("No password was reset....\nHit return to continue...");
}
Aggregations