You need to sign in to do that
Don't have an account?
yagna
Need help for fixing upsertion errors
We have been trying to upsert a record into a custom object. We used the quickstart code along with some modifications.
Description of the custom object :
Name of the object : GP_Calc__c
Custom Fields : 1) createdById 6) lastModifiedDate 11) schedule_Date__c
2) createdDate 7) name 12) systemModstamp
3) external_ID__c 8) opportunity__c
4) GP_Amount__c 9) product2__c
5) lastModifiedById 10) schedule_Amount__c
we have created the following code for upserting into the custom object. we have taken the OpportunityLineItemID and ProductID from a earlier query. we are using an Eclipse3.1 IDE.
public void upsertGp()
{
// create an array of SObjects to send to the //upsert method
SObject[] upserts = new GP_Calc__c[1];
// this account is meant to be new
GP_Calc__c upsertgp = new GP_Calc__c();
ID opportunityid = new ID("00620000001qpacAAA");
upsertgp.setOpportunity__c(opportunityid);
ID productid = new ID("01u20000000JF17AAG");
upsertgp.setProduct2__c(productid);
upsertgp.setExternal_ID__c("1111111111");
upsertgp.setName("tidel park");
upserts[0]=upsertgp;
try {
System.out.println("inside the try block");
// invoke the upert call and save the results .
// use External_Id custom field for matching //records
UpsertResult[] upsertResults = binding.upsert("External_Id__c", upserts);
UpsertResult upsertresult=null;
upsertresult=upsertResults[0];
// we are checking if the upert was a success or not
if(upsertresult.isSuccess()) {
System.out.println(upsertresult.isSuccess()+"\n");
System.out.println("\nthe upsertion is a success\n");
System.exit(0);
}
else {
System.out.println(upsertresult.getErrors()+"\n");
System.out.println("\nthe upsertion was a fiasco\n");
System.exit(1);
}
} catch(RemoteException ex) {
System.out.println("An unexpected error has occurred....."+ ex.getMessage());
}
getUserInput("\nPress the RETURN key to continue...");
}
{
// create an array of SObjects to send to the //upsert method
SObject[] upserts = new GP_Calc__c[1];
// this account is meant to be new
GP_Calc__c upsertgp = new GP_Calc__c();
ID opportunityid = new ID("00620000001qpacAAA");
upsertgp.setOpportunity__c(opportunityid);
ID productid = new ID("01u20000000JF17AAG");
upsertgp.setProduct2__c(productid);
upsertgp.setExternal_ID__c("1111111111");
upsertgp.setName("tidel park");
upserts[0]=upsertgp;
try {
System.out.println("inside the try block");
// invoke the upert call and save the results .
// use External_Id custom field for matching //records
UpsertResult[] upsertResults = binding.upsert("External_Id__c", upserts);
UpsertResult upsertresult=null;
upsertresult=upsertResults[0];
// we are checking if the upert was a success or not
if(upsertresult.isSuccess()) {
System.out.println(upsertresult.isSuccess()+"\n");
System.out.println("\nthe upsertion is a success\n");
System.exit(0);
}
else {
System.out.println(upsertresult.getErrors()+"\n");
System.out.println("\nthe upsertion was a fiasco\n");
System.exit(1);
}
} catch(RemoteException ex) {
System.out.println("An unexpected error has occurred....."+ ex.getMessage());
}
getUserInput("\nPress the RETURN key to continue...");
}
when we try to run the above code it throws the following error.
[Lcom.sforce.soap.enterprise.Error;@340101
We would like to have some information about this error and how to fix it as soon as possible.
Superfell
upsertresult.getErrors() returns you an array of errors, look at the status code and message of the first error in the array.