+ Start a Discussion
doubleminusdoubleminus 

Problem creating records

The sample code from here does not work.

 

public boolean createAccountSample()
{
// Create two account objects
Account account1 = new Account();
Account account2 = new Account();

// Set some fields on the account object
// Name field (required) not being set on account1,
// so this record should fail during create.
account1.setAccountNumber("002DF99ELK9");
account1.setBillingCity("Wichita");
account1.setBillingCountry("US");
account1.setBillingState("KA");
account1.setBillingStreet("4322 Haystack Boulevard");
account1.setBillingPostalCode("87901");

// Set some fields on the account2 object
account2.setName("Golden Straw");
account2.setAccountNumber("003DF99ELK9");
account2.setBillingCity("Oakland");
account2.setBillingCountry("US");
account2.setBillingState("CA");
account2.setBillingStreet("666 Raiders Boulevard");
account2.setBillingPostalCode("97502");

// Create an array of SObjects to hold the accounts
SObject[] sObjects = new SObject[2];
// Add the accounts to the SObject array
sObjects[0] = account1;
sObjects[1] = account2;

// Invoke the create call
try {
SaveResult[] saveResults = binding.create(sObjects);

// Handle the results
for (int i=0; i<saveResults.length; i++) {
// Determine whether create succeeded or had errors
if (saveResults[i].isSuccess()) {
// No errors, so we will retrieve the id created for this index
System.out.println(saveResults[i].getId());
}
else {
// Handle the errors
System.out.println("Item " + i + " had an error updating.");
System.out.println("The error reported was: " +
saveResults[i].getErrors()[0].getMessage() + "\n");
}
}
} catch (InvalidSObjectFault e) {
System.out.println("Invalid object exception encountered:\n\n" + e.getMessage());
return false;
} catch (UnexpectedErrorFault e) {
System.out.println("Unexpected error exception encountered:\n\n" + e.getMessage());
return false;
} catch (InvalidIdFault e) {
System.out.println("Invalid Id exception encountered:\n\n" + e.getMessage());
return false;
} catch (RemoteException e) {
System.out.println("Remote exception encountered:\n\n" + e.getMessage());
return false;
}
return true;}

 

The problem is with the key piece: invoking the create call.

 

binding.create(sObjects);

 

I show the create() method as using a QName parameter, not an sObjects array parameter. Is there something I'm missing here? Please advise.

 

thx,

double

mpiercempierce
What WSDL and SOAP stack are you using?
doubleminusdoubleminus
enterprise and apache cxf