Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to make upsert in salesforce work instead of inserting new duplicate records?

Asked by David Edmunds May 23, 2023 1.2K views 1 answer
Share

About this question

My Object Test__c has two lookup
Emp__c - 1st lookup
Score__c -2nd lookup
I have populated all the values.
upsert (new Test__c(emp__c = 'XXXX',score__c = '123')); upsert (new Test__c(emp__c = 'XXXX',score__c = '123'));
Does it create two records ? I guess it sounds 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 checked while creating a 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.

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.