function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kman1976Kman1976 

How to find which Upsert Records were failed from UpsertResult Object ?

I have a code in java that upserts Orders & OrderLine Items for custom objects .In the code i set "AllOrNoneHeader" to true to make sure all the line items are successfully inserted other wise roll back everything. I am having hard time to identify which records were exactly failed during upsert.Any idea how to identify those records for further data related investigation.I am trying to exactly identify which records are failing in "objNewOrderLineItems" object in the below code?.

 

Here "objNewOrderLineItems" is of type SObject[]

 

Here is the sample code:

 

                connection.setAllOrNoneHeader(true);
                //MsgOut("SFDCQueryDump>>"+objNewOrderLineItems[0].toString());
                UpsertResult[] upsertResults =connection.upsert("recId_ord_dtl__c", objNewOrderLineItems);
              
                for (UpsertResult result : upsertResults)
                {
                  if (result.isSuccess()) {
                   UpsertLineItemsStatus=true;
                   //MsgOut("\nLineItem Upsert Succeeded.");
                   //MsgOut((result.isCreated() ? "Insert" : "Update") +" was performed."+" With OrderLineItem__C ID: " + result.getId());
                   //MsgOut("OrderLineItem__C ID: " + result.getId());
                  } else
                  {
                   MsgOut("LineItem Upsert Failed Because::" +result.getErrors()[0].getStatusCode());
                   result.get
                   Glbl_ErrorMsg=Glbl_ErrorMsg+"-/-"+result.getErrors()[0].getMessage();
                   UpsertLineItemsStatus=false;
                  }
                }//UpsertResult forloop

 

I get the error message as follows..

LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::INVALID_FIELD_FOR_INSERT_UPDATE
LineItem Upsert Failed Because::INVALID_FIELD_FOR_INSERT_UPDATE
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK
LineItem Upsert Failed Because::ALL_OR_NONE_OPERATION_ROLLED_BACK