Search in sources :

Example 11 with SObject

use of com.salesforce.soap.partner.sobject.SObject 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...");
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) ResetPasswordResult(com.salesforce.soap.partner.ResetPasswordResult) RemoteException(java.rmi.RemoteException)

Example 12 with SObject

use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.

the class PartnerSamples method queryAllSample.

private void queryAllSample() {
    // 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;
    }
    createAndDeleteAnAccount(accountName);
    // Now for Query All. Query all allows you to return items that have been moved to the recycle
    // bin, like the account we just deleted.
    QueryResult qr = null;
    try {
        qr = binding.queryAll("select id, Name from Account where name = '" + accountName + "' and IsDeleted = true");
        if (qr.getSize() != 0) {
            SObject account = qr.getRecords()[0];
            System.out.println("Retrieved the deleted account: " + getFieldValue(account.get_any(), "Name"));
        } else {
            System.out.println("Hmm...\nDid not find the account, that's strange.");
        }
        System.out.println("\nQuery succesfully executed.");
        getUserInput("\nHit return to continue...");
    } catch (ApiFault af) {
        System.out.println("\nFailed to execute query succesfully, error message was: \n" + af.getExceptionMessage());
        getUserInput("\nHit return to continue...");
    } catch (Exception ex) {
        System.out.println("\nFailed to execute query succesfully, error message was: \n" + ex.getMessage());
        getUserInput("\nHit return to continue...");
    }
}
Also used : QueryResult(com.salesforce.soap.partner.QueryResult) ApiFault(com.salesforce.soap.partner.fault.ApiFault) SObject(com.salesforce.soap.partner.sobject.SObject) RemoteException(java.rmi.RemoteException) ServiceException(javax.xml.rpc.ServiceException) IOException(java.io.IOException)

Example 13 with SObject

use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.

the class SforceManagementImpl method upsert.

/**
     * upsert, one record, one time.
     */
@Override
public UpsertResult[] upsert(String tablename, String upsertkey, OMElement[] updatefields, String[] fieldsToNull) throws Exception {
    // create the account object to hold our changes
    SObject item = new SObject();
    item.setType(tablename);
    // set a new value for the name property
    item.setExtraElement(updatefields);
    // set a null field for the name property
    item.setFieldsToNull(fieldsToNull);
    upsertItems.add(item);
    upsertKeyColumn = upsertkey;
    // call the update passing an array of object
    if (upsertItems.size() >= commitLevel) {
        SObject[] upds = upsertItems.toArray(new SObject[upsertItems.size()]);
        String[] changedItemKeys = new String[upds.length];
        for (int ix = 0; ix < upds.length; ++ix) {
            changedItemKeys[ix] = "No value for " + upsertKeyColumn + " ";
            OMElement[] oms = upds[ix].getExtraElement();
            for (OMElement om : oms) {
                if (upsertKeyColumn != null && om != null && upsertKeyColumn.equals(om.getLocalName())) {
                    changedItemKeys[ix] = om.getText();
                    break;
                }
            }
        }
        Upsert upsert = new Upsert();
        upsert.setSObjects(upds);
        upsert.setExternalIDFieldName(upsertKeyColumn);
        UpsertResult[] upsertResults = sforceConn.upsert(upsert).getResult();
        upsertItems.clear();
        upds = null;
        if (upsertResults != null && upsertResults.length != 0) {
            int batch_idx = -1;
            for (UpsertResult result : upsertResults) {
                ++batch_idx;
                StringBuilder errors = new StringBuilder("");
                if (result.getSuccess()) {
                // TODO: send back the ID
                } else {
                    errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
                }
                if (exceptionForErrors && errors.toString().length() > 0) {
                    if (logWriter != null) {
                        logWriter.close();
                    }
                    throw new Exception(errors.toString());
                }
            }
        }
        return upsertResults;
    }
    return null;
}
Also used : Upsert(com.salesforce.soap.partner.Upsert) DescribeSObject(com.salesforce.soap.partner.DescribeSObject) SObject(com.salesforce.soap.partner.sobject.SObject) OMElement(org.apache.axiom.om.OMElement) UpsertResult(com.salesforce.soap.partner.UpsertResult)

Example 14 with SObject

use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.

the class SforceManagementImpl method retrieve.

@Override
public SObject[] retrieve(ID[] ids, String objectType, String fieldsList) throws Exception {
    Retrieve retrieve = new Retrieve();
    retrieve.setFieldList(fieldsList);
    retrieve.setIds(ids);
    retrieve.setSObjectType(objectType);
    SObject[] results = sforceConn.retrieve(retrieve).getResult();
    // }
    return results;
}
Also used : Retrieve(com.salesforce.soap.partner.Retrieve) DescribeSObject(com.salesforce.soap.partner.DescribeSObject) SObject(com.salesforce.soap.partner.sobject.SObject)

Example 15 with SObject

use of com.salesforce.soap.partner.sobject.SObject in project tdi-studio-se by Talend.

the class SforceManagementImpl method insert.

/**
     * create, one time one record.
     */
@Override
public SaveResult[] insert(String tablename, OMElement[] nameValues) throws Exception {
    if (tablename == null || tablename.trim().length() == 0) {
        return null;
    }
    if (nameValues == null || nameValues.length == 0) {
        return null;
    }
    SObject item = new SObject();
    item.setType(tablename);
    item.setExtraElement(nameValues);
    // item.setId("00T9000000VLEqBDAX");
    insertItems.add(item);
    if (insertItems.size() >= commitLevel) {
        SObject[] accs = insertItems.toArray(new SObject[insertItems.size()]);
        String[] changedItemKeys = new String[accs.length];
        Create create = new Create();
        create.setSObjects(accs);
        SaveResult[] sr = sforceConn.create(create).getResult();
        insertItems.clear();
        accs = null;
        if (sr != null && sr.length != 0) {
            int batch_idx = -1;
            for (SaveResult result : sr) {
                ++batch_idx;
                StringBuilder errors = new StringBuilder("");
                if (result.getSuccess()) {
                // TODO: send back the ID
                } else {
                    errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? "" + (batch_idx + 1) : "Batch index out of bounds");
                }
                if (exceptionForErrors && errors.toString().length() > 0) {
                    if (logWriter != null) {
                        logWriter.close();
                    }
                    throw new Exception(errors.toString());
                }
            }
        }
        return sr;
    }
    return null;
}
Also used : Create(com.salesforce.soap.partner.Create) DescribeSObject(com.salesforce.soap.partner.DescribeSObject) SObject(com.salesforce.soap.partner.sobject.SObject) SaveResult(com.salesforce.soap.partner.SaveResult)

Aggregations

SObject (com.salesforce.soap.partner.sobject.SObject)25 RemoteException (java.rmi.RemoteException)17 IOException (java.io.IOException)15 ServiceException (javax.xml.rpc.ServiceException)15 ApiFault (com.salesforce.soap.partner.fault.ApiFault)14 QueryResult (com.salesforce.soap.partner.QueryResult)10 SaveResult (com.salesforce.soap.partner.SaveResult)9 MessageElement (org.apache.axis.message.MessageElement)7 DescribeSObject (com.salesforce.soap.partner.DescribeSObject)5 UpsertResult (com.salesforce.soap.partner.UpsertResult)3 OMElement (org.apache.axiom.om.OMElement)3 Create (com.salesforce.soap.partner.Create)2 DeleteResult (com.salesforce.soap.partner.DeleteResult)2 ID (com.salesforce.soap.partner.ID)2 Update (com.salesforce.soap.partner.Update)2 Upsert (com.salesforce.soap.partner.Upsert)2 HashMap (java.util.HashMap)2 Delete (com.salesforce.soap.partner.Delete)1 DeleteResponse (com.salesforce.soap.partner.DeleteResponse)1 DescribeSObjectResult (com.salesforce.soap.partner.DescribeSObjectResult)1