Search in sources :

Example 16 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.

the class PartnerSamples method createContactSample.

private void createContactSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        SObject[] cons = new SObject[2];
        MessageElement[] contact;
        for (int j = 0; j < cons.length; j++) {
            int index = 0;
            if (accounts != null) {
                contact = new MessageElement[18];
                contact[index++] = newMessageElement("AccountId", accounts[0]);
            } else {
                contact = new MessageElement[17];
            }
            contact[index++] = newMessageElement("AssistantName", "Jane");
            contact[index++] = newMessageElement("AssistantPhone", "777.777.7777");
            contact[index++] = newMessageElement("Department", "Purchasing");
            contact[index++] = newMessageElement("Description", "International IT Purchaser");
            contact[index++] = newMessageElement("Email", "joeblow@isp.com");
            contact[index++] = newMessageElement("Fax", "555.555.5555");
            contact[index++] = newMessageElement("MailingCity", "San Mateo");
            contact[index++] = newMessageElement("MailingCountry", "US");
            contact[index++] = newMessageElement("MailingState", "CA");
            contact[index++] = newMessageElement("MailingStreet", "1129 B Street");
            contact[index++] = newMessageElement("MailingPostalCode", "94105");
            contact[index++] = newMessageElement("MobilePhone", "888.888.8888");
            contact[index++] = newMessageElement("FirstName", "Joe");
            contact[index++] = newMessageElement("LastName", "Blow");
            contact[index++] = newMessageElement("Salutation", "Mr.");
            contact[index++] = newMessageElement("Phone", "999.999.9999");
            contact[index++] = newMessageElement("Title", "Purchasing Director");
            cons[j] = new SObject();
            cons[j].setType("Contact");
            cons[j].set_any(contact);
        }
        SaveResult[] sr = binding.create(cons);
        for (int j = 0; j < sr.length; j++) {
            if (sr[j].isSuccess()) {
                System.out.println("A contact was create with an id of: " + sr[j].getId());
                if (accounts != null) {
                    System.out.println(" - the contact was associated with the account you created with an id of " + accounts[0] + ".");
                }
                if (contacts == null) {
                    contacts = new String[] { sr[j].getId() };
                } else {
                    String[] tempContacts = null;
                    tempContacts = new String[contacts.length + 1];
                    for (int i = 0; i < contacts.length; i++) {
                        tempContacts[i] = contacts[i];
                    }
                    tempContacts[contacts.length] = sr[j].getId();
                    contacts = tempContacts;
                }
            } 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 contacts, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to create contacts, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : MessageElement(org.apache.axis.message.MessageElement) SaveResult(com.salesforce.soap.partner.SaveResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject)

Example 17 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.

the class PartnerSamples method describeSample.

private void describeSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    String objectToDescribe = getUserInput("\nType the name of the object to describe (try Account): ");
    try {
        DescribeSObjectResult ds;
        DescribeSObjectResult describeSObjectResult = binding.describeSObject(objectToDescribe);
        if (!(describeSObjectResult == null)) {
            Field[] fields = describeSObjectResult.getFields();
            String objectName = describeSObjectResult.getName();
            boolean isActivateable = describeSObjectResult.isActivateable();
            boolean isCreateable = describeSObjectResult.isCreateable();
            boolean isCustom = describeSObjectResult.isCustom();
            boolean isDeleteable = describeSObjectResult.isDeletable();
            boolean isQueryable = describeSObjectResult.isQueryable();
            boolean isReplicateable = describeSObjectResult.isReplicateable();
            boolean isRetrieveable = describeSObjectResult.isRetrieveable();
            boolean isSearchable = describeSObjectResult.isSearchable();
            boolean isUndeleteable = describeSObjectResult.isUndeletable();
            boolean isUpdateable = describeSObjectResult.isUpdateable();
            System.out.println("Metadata for " + objectToDescribe + " object:\n");
            System.out.println("Object name                       = " + objectName);
            System.out.println("Number of fields                  = " + fields.length);
            System.out.println("Object can be activated           = " + isActivateable);
            System.out.println("Can create rows of data           = " + isCreateable);
            System.out.println("Object is custom object           = " + isCustom);
            System.out.println("Can delete rows of data           = " + isDeleteable);
            System.out.println("Can query for rows of data        = " + isQueryable);
            System.out.println("Object can be used in replication = " + isReplicateable);
            System.out.println("Can use retrieve method on object = " + isRetrieveable);
            System.out.println("Can use search method on object   = " + isSearchable);
            System.out.println("Can un-delete rows of data        = " + isUndeleteable);
            System.out.println("Can update rows of data           = " + isUpdateable);
            System.out.println("\nField metadata for " + objectToDescribe + " object:\n");
            if (!(fields == null)) {
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    int byteLength = field.getByteLength();
                    int digits = field.getDigits();
                    String label = field.getLabel();
                    int length = field.getLength();
                    String name = field.getName();
                    PicklistEntry[] picklistValues = field.getPicklistValues();
                    int precision = field.getPrecision();
                    String[] referenceTos = field.getReferenceTo();
                    int scale = field.getScale();
                    FieldType fieldType = field.getType();
                    boolean fieldIsAutoNumber = field.isAutoNumber();
                    boolean fieldIsCreateable = field.isCreateable();
                    boolean fieldIsCustom = field.isCustom();
                    boolean fieldIsDefaultedOnCreate = field.isDefaultedOnCreate();
                    boolean fieldIsFilterable = field.isFilterable();
                    boolean fieldIsNillable = field.isNillable();
                    boolean fieldIsRestrictedPicklist = field.isRestrictedPicklist();
                    boolean fieldIsUpdateable = field.isUpdateable();
                    System.out.println("*************  New Field  ***************");
                    System.out.println("Name            = " + name);
                    System.out.println("Label           = " + label);
                    System.out.println("Length          = " + length);
                    System.out.println("Bytelength      = " + byteLength);
                    System.out.println("Digits          = " + digits);
                    System.out.println("Precision       = " + precision);
                    System.out.println("Scale           = " + scale);
                    System.out.println("Field type      = " + fieldType);
                    if (picklistValues != null) {
                        System.out.println("Picklist values = ");
                        for (int j = 0; j < picklistValues.length; j++) {
                            if (picklistValues[j].getLabel() != null) {
                                System.out.println("    Item:  " + picklistValues[j].getLabel());
                            } else {
                                System.out.println("    Item:  " + picklistValues[j].getValue());
                            }
                            System.out.println("        value           = " + picklistValues[j].getValue());
                            System.out.println("        is default      = " + picklistValues[j].isDefaultValue());
                        }
                    }
                    if (referenceTos != null) {
                        System.out.println("Field references the following objects:");
                        for (int j = 0; j < referenceTos.length; j++) {
                            System.out.println("    " + referenceTos[j]);
                        }
                    }
                    System.out.println("\n");
                }
                getUserInput("\nDescribe " + objectToDescribe + " was successful.\n\nHit the enter key to conutinue....");
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to get " + objectToDescribe + " description, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get " + objectToDescribe + " description, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : Field(com.salesforce.soap.partner.Field) DescribeSoftphoneLayoutInfoField(com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField) ApiFault(com.salesforce.soap.partner.fault.ApiFault) DescribeSObjectResult(com.salesforce.soap.partner.DescribeSObjectResult) PicklistEntry(com.salesforce.soap.partner.PicklistEntry) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) FieldType(com.salesforce.soap.partner.FieldType)

Example 18 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.

the class PartnerSamples method undeleteSample.

private void undeleteSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    // For this sample we will create an account and then delete it
    // to demonstrate the power of queryAll
    String accountName = getUserInput("\nEnter a name for a test account:");
    if (accountName == null || accountName.length() == 0) {
        return;
    }
    String accountId = createAndDeleteAnAccount(accountName);
    getUserInput("You can check your recycle bin now to see the deleted account.\nHit return to continue...");
    // Now, we can undelete the account
    try {
        UndeleteResult udr = binding.undelete(new String[] { accountId })[0];
        if (udr.isSuccess()) {
            System.out.println("The account was successfully undeleted.");
            System.out.println("If you check your recycle bin you will see the account is no longer present.");
        } else {
            System.out.println("Undelete failed: " + udr.getErrors(0).getMessage());
        }
    } catch (ApiFault e) {
        System.out.println("Error un-deleting test account: " + e.getExceptionMessage());
    } catch (RemoteException e) {
        System.out.println("Error from the server on create test account: " + e.getMessage());
    }
    getUserInput("\nHit return to continue...");
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) UndeleteResult(com.salesforce.soap.partner.UndeleteResult) RemoteException(java.rmi.RemoteException)

Example 19 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.

the class PartnerSamples method describeSObjectsSample.

private void describeSObjectsSample() {
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        DescribeSObjectResult[] describeSObjectResults = binding.describeSObjects(new String[] { "account", "contact", "lead" });
        for (int x = 0; x < describeSObjectResults.length; x++) {
            DescribeSObjectResult describeSObjectResult = describeSObjectResults[x];
            // Retrieve fields from the results
            Field[] fields = describeSObjectResult.getFields();
            // Get the name of the object
            String objectName = describeSObjectResult.getName();
            // Get some flags
            boolean isActivateable = describeSObjectResult.isActivateable();
            // Many other values are accessible
            if (fields != null) {
                // field
                for (int i = 0; i < fields.length; i++) {
                    Field field = fields[i];
                    int byteLength = field.getByteLength();
                    int digits = field.getDigits();
                    String label = field.getLabel();
                    int length = field.getLength();
                    String name = field.getName();
                    PicklistEntry[] picklistValues = field.getPicklistValues();
                    int precision = field.getPrecision();
                    String[] referenceTos = field.getReferenceTo();
                    int scale = field.getScale();
                    FieldType fieldType = field.getType();
                    boolean fieldIsCreateable = field.isCreateable();
                    // Determine whether there are picklist values
                    if (picklistValues != null && picklistValues[0] != null) {
                        System.out.println("Picklist values = ");
                        for (int j = 0; j < picklistValues.length; j++) {
                            if (picklistValues[j].getLabel() != null) {
                                System.out.println(" Item: " + picklistValues[j].getLabel());
                            }
                        }
                    }
                    // Determine whether this field refers to another object
                    if (referenceTos != null && referenceTos[0] != null) {
                        System.out.println("Field references the following objects:");
                        for (int j = 0; j < referenceTos.length; j++) {
                            System.out.println(" " + referenceTos[j]);
                        }
                    }
                }
            }
        }
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to get describe multiple objects, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to get describe multiple objects, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : DescribeSObjectResult(com.salesforce.soap.partner.DescribeSObjectResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException) FieldType(com.salesforce.soap.partner.FieldType) Field(com.salesforce.soap.partner.Field) DescribeSoftphoneLayoutInfoField(com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField) ApiFault(com.salesforce.soap.partner.fault.ApiFault) PicklistEntry(com.salesforce.soap.partner.PicklistEntry)

Example 20 with ApiFault

use of com.salesforce.soap.partner.fault.ApiFault in project tdi-studio-se by Talend.

the class PartnerSamples method updateAccountSample.

private void updateAccountSample() {
    // call the login function to do so
    if (!loggedIn) {
        if (!login()) {
            return;
        }
    }
    try {
        // check to see if there are any accounts created in this session
        if (accounts == null) {
            System.out.println("\nUpdate operation not completed.  You will need to create an account during this session to run the update sample.");
            getUserInput("\nHit return to continue...");
            return;
        }
        // create the account object to hold our changes
        SObject updateAccount = new SObject();
        updateAccount.setType("Account");
        // need to have the id so that web service knows which account to
        // update
        updateAccount.setId(accounts[0]);
        // set a new value for the name property
        MessageElement[] ufields = new MessageElement[1];
        ufields[0] = newMessageElement("Name", "New Account Name from Update Sample");
        updateAccount.set_any(ufields);
        // create one that will throw an error
        SObject errorAccount = new SObject();
        errorAccount.setType("Account");
        errorAccount.setId(new String("SLFKJLFKJ"));
        errorAccount.setFieldsToNull(new String[] { "Name" });
        // call the update passing an array of object
        SaveResult[] saveResults = binding.update(new SObject[] { updateAccount, errorAccount });
        // loop through the results, checking for errors
        for (int j = 0; j < saveResults.length; j++) {
            System.out.println("Item: " + new Integer(j).toString());
            if (saveResults[j].isSuccess()) {
                System.out.println("An account with an id of: " + saveResults[j].getId() + " was updated.\n");
            } else {
                System.out.println("Item " + new Integer(j).toString() + " had an error updating.");
                System.out.println("    The error reported was: " + saveResults[j].getErrors()[0].getMessage() + "\n");
            }
        }
    } catch (ApiFault af) {
        System.out.println("\nFailed to succesfully update an account, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to succesfully update an account, error message was: \n" + ex.getMessage());
    }
    getUserInput("\nHit return to continue...");
}
Also used : ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) MessageElement(org.apache.axis.message.MessageElement) SaveResult(com.salesforce.soap.partner.SaveResult) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Aggregations

ApiFault (com.salesforce.soap.partner.fault.ApiFault)25 RemoteException (java.rmi.RemoteException)25 ServiceException (javax.xml.rpc.ServiceException)20 IOException (java.io.IOException)19 SObject (com.salesforce.soap.partner.sobject.SObject)14 MessageElement (org.apache.axis.message.MessageElement)8 QueryResult (com.salesforce.soap.partner.QueryResult)6 SaveResult (com.salesforce.soap.partner.SaveResult)6 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)3 DescribeSoftphoneLayoutInfoField (com.salesforce.soap.partner.DescribeSoftphoneLayoutInfoField)3 GregorianCalendar (java.util.GregorianCalendar)3 HashMap (java.util.HashMap)3 Field (com.salesforce.soap.partner.Field)2 FieldType (com.salesforce.soap.partner.FieldType)2 PicklistEntry (com.salesforce.soap.partner.PicklistEntry)2 SforceServiceLocator (com.salesforce.soap.partner.SforceServiceLocator)2 ArrayList (java.util.ArrayList)2 DeleteResult (com.salesforce.soap.partner.DeleteResult)1 DescribeLayout (com.salesforce.soap.partner.DescribeLayout)1 DescribeLayoutItem (com.salesforce.soap.partner.DescribeLayoutItem)1