function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vincent.IpVincent.Ip 

Upsert Error "Duplicate id in list: false"

This is more of an FYI, as i did seem to find any where else this was posted.  Hopefully this saves someone from a headache.

I was getting an error message "Duplicate id in list: false" from the following statements.  The exception itself was from the upsert statement.

    List<Chat_Transcript__c> allTranscripts;

    ...
    for ( ... ){
        Chat_Transcript__c currChat = new Chat_Transcript__c();

        ....

        allTranscripts.add(currChat);
    }
    ...
    upsert allTranscripts Chat_Number__c;
 
The records in the allTranscripts had an externalId put into the Chat_Number__c field and all Chat_Transcript__c records in the list were created programmatically with a new Chat_Transcript() statement.  I double checked to make sure that the records within the list did not have duplicate Chat_Number__c values.

Not sure when this bug seemed to show up, but upserting like this caused the error message to appear.  I fixed this by adding the following to the code.
 
 
    List<Chat_Transcript__c> allTranscripts;

    ...
    for ( ... ){
        Chat_Transcript__c currChat = new Chat_Transcript__c();

        currChat.Id = null;
        ....

        allTranscripts.add(currChat);
    }
    ...
    upsert allTranscripts Chat_Number__c;



Don't know if anyone else was having this problem, but hopefully this fix helps you.
Shikha AgashiShikha Agashi
Use SET for upsert operation instead of LIST. Use Set<Chat_Transcript__c> allTranscripts = new Set<Chat_Transcript__c>(); instead of List<Chat_Transcript__c> allTranscripts;
Srinivasa Chary TaduriSrinivasa Chary Taduri
Set<Chat_Transcript__c> allTranscriptsSet = new Set<Chat_Transcript__c>();
allTranscriptsSet.addAll(allTranscripts); // Eleminating duplicates
allTranscripts.clear();
allTranscripts.addAll(allTranscriptsSet);// Put it back
upsert allTranscripts; // Upsert the deduplicate records