UpsertResult[] ur= connection.upsert(String externalIdFieldName, sObject[] sObjects);
Upsert is creates new records and updates existing records; uses a custom field to determine the presence of existing records. Use upsert() instead of create() to avoid creating unwanted duplicate records You can process records for the one more than object type in an create() or update() call, but all records must have same object type in an upsert() call.
Upsert is merging of the words insert and update. This call is available for the objects if the object has an external ID field or a field with the idLookup field property.
Select update/create:
* If external ID is not matched, then a new record is created.
* If external ID is matched once, then the existing record is updated.
* If external ID is matched multiple times, then an error is reported.
* When batch updating multiple records where the external ID is the same for two or more records in your batch call, those records will be marked as errors in the UpsertResult file. The records will be neither created nor updated.
Sample Code:
			Post Views: 

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.