My Object
Test__c
has two lookup
Emp__c
– 1st lookup
Score__c
-2nd lookup
I have populated all the value.
upsert (new Test__c(emp__c = 'XXXX',score__c = '123'));
upsert (new Test__c(emp__c = 'XXXX',score__c = '123'));
It create two record ? i guess its sound silly ? But wanna check the clear idea behind the upsert ?
Thanks All….! I just completely understand that it is only based on
the ID or External Id. I did an example with my test object. Working
awesome…
External_Id__c – Is a text field with the external ID is checked while creating field.
I have a record with the same external id ie. Name = Test1, Exception = Ex1
PAK09_Test1__c ct2 = new PAK09_Test1__c(Name ='Test3',
Exception__c='Ex3',
External_Id__c='123');
database.upsert(ct2, PAK09_Test1__c.Fields.External_Id__c);
Existing record is updated with Name = Test3,Exception = Ex3.
Best Answer
From documentation:
Couple of points to remember:
If the key is not matched, a new object record is created.
If the key is matched once, the existing object record is updated.
If the key is matched multiple times, an error is generated and the object record is neither inserted or updated.
So it's quite clear how upsert statement works and what are configurable paramters. So in your case it's likely to create two records since there is no any indexed field i.e.
id
orexternalId
to detect duplicate records.