1

I'm getting the following error 'System.ListException: Before Insert or Upsert list must not have two identically equal elements' when i'm trying below code

Map<Id,SBQQ__QuoteLine__c> parentQuoteLines = new Map<Id,SBQQ__QuoteLine__c>();

for(SBQQ__QuoteLine__c  qli : qliToInsert){

if( String.isBlank(qli.SBQQ__RequiredBy__r.Id) 
                            && !parentQuoteLines .containsKey(qli.Id) 
   &&qliprodCodetoRecordMap.containsKey(qli.SBQQ__Product__c)){
                                parentQuoteLines.put(qli.Id,qliprodCodetoRecordMap.get(qli.SBQQ__Product__c));
                        }

if(!parentQuoteLines .values().isEmpty()){

    insert parentQuoteLines .values(); // Getting error when inserting
}
4
  • What does this map qliprodCodetoRecordMap stores? There is a possibility that same record has been added in map. Dec 17 '19 at 9:46
  • qliprodCodetoRecordMap it stores Quoteline fields related to that qli.id.
    – Nitesh
    Dec 17 '19 at 13:28
  • Below answer should solve your problem. Dec 17 '19 at 13:31
  • I guess code variables are confusing, so edited the code have a look. Thanks Nitesh
    – Nitesh
    Dec 18 '19 at 6:34
2

This:

parentProducts.put(qli.Id, qliprodCodetoRecordMap.get(qli.Id));

or this (more likely what you want):

parentProducts.put(qli.SBQQ__Product__c, qliprodCodetoRecordMap.get(qli.SBQQ__Product__c));

or this (cleaner code version):

SBQQ__QuoteLine__c pqli = qliprodCodetoRecordMap.get(qli.SBQQ__Product__c);
parentProducts.put(pqli.Id, pqli);

would avoid duplicate records but this mixture that you are using will not:

parentProducts.put(qli.Id, qliprodCodetoRecordMap.get(qli.SBQQ__Product__c));
1
  • i guess code variables are confusing, i have edited the code please have a look. thanks nitesh
    – Nitesh
    Dec 18 '19 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.