Database.Upsert – Get Which Records are Inserted or Updated Based on External Id

Sample Code:

Database.UpsertResult[] results = Database.upsert(accList, Account.ExternalId__c);
for(Integer i = 0, i < results.size(); i++) {
    if(results[i].isSuccess()) {
        if(results[i].isCreated()) {
            System.debug(accList[i].ExternalId__c +' was created');
        } else {
            System.debug(accList[i].ExternalId__c +' was updated');
        }
    }
}