I am upserting list of records based on externalId as follows:
List<Database.upsertResult> results = Database.upsert(lstRecords, CustomObject__c.External_Id__c,true);
The results returns as follows:
(Database.UpsertResult[getErrors=();
getId=a1k0j000000P6CmAAK;
isCreated=true;
isSuccess=true;],
Database.UpsertResult[getErrors=();
getId=a1k0j000000P6CNAA0;
isCreated=false;
isSuccess=true;])
The first record is inserted and 2nd record is updated.
Since I am upserting based on externalId, I need to know for which ExternalId the records have been successfully inserted or updated.
UpsertResult Class doesn't expose any methods. It returns SalesforceId and NOT externalId
I need a results structure like this:
(Database.UpsertResult[getErrors=();
getExternalId = '1234';
getId=a1k0j000000P6CmAAK;
isCreated=true;
isSuccess=true;],
Database.UpsertResult[getErrors=();
getExternalId = '1235';
getId=a1k0j000000P6CNAA0;
isCreated=false;
isSuccess=true;])
What would be the best way to achieve this.