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
NerijusNerijus 

"Duplicate id in list" but when trying to open that record by id it does not exist

I'm getting this error, but when I try to open a record it's not there.
NerijusNerijus
I like to add that I cleaned recycle bin because I know that file can still be there with isDeleted flag.
paul diracpaul dirac
If the id is created but not inserted then at the end of your transaction the id is discarded if not inserted. Check your logs and try to catch exceptions if there are.
NerijusNerijus
I get this from current records. So I loop through the list of existing records and try to delete them and on delete I get that error
paul diracpaul dirac

So if you perform an undelete action on that record what's the error message? 

try:

 

try {
    undelete *yourrecord*;
} catch (DmlException e) {
    // print message
}
NerijusNerijus
Here is what I try to execute:
OpportunityLineItemSchedule sch = [SELECT Id FROM OpportunityLineItemSchedule WHERE Id = '00o4H000003lxWbQAI' ALL ROWS];
try {
    undelete sch;
} catch (DmlException e){
    System.debug(e);
}

Error:
System.QueryException: List has no rows for assignment to SObject
NerijusNerijus
Ok I got this error because I used single OpportunityLineItemSchedule object. If I use list I get no error and debug log doesn't print anything and still that record is not existant
NerijusNerijus
User-added image
paul diracpaul dirac
So how do you get the 'Duplicate id in list' error?
NerijusNerijus
Well that's what I'm asking. Code that being executed is a bit messy so it's hard to follow. But still I shouldn't get that error if record is non existant.
paul diracpaul dirac
I mean, what are you doing at that point in which your code breaks?
paul diracpaul dirac
Just provide some prsudocode of what you are doin
NerijusNerijus
We use CPQ package and code runs if any amendment opportunities gets closed won, so basically:
  • Code tries to figure out opportunity that is being amended
  • Then queries opportunity line items and product schedules
  • Then checks if product schedule date is > then new product start date
  • If so it adds all schedules to the list and deletes them
This is very short version of the logic. I get that error on delete. Let me know if more details are necessary
paul diracpaul dirac
Are you performing that delete inside a trigger or a regular apex class?
Once you are ready to formalize this question technically speaking, consider to post your question on salesforce stack exchange, but you have to specify a lot of details (not the actual code necessary) since this issue seems to be a little tricky and referred to that package.
The steps you provide are not enought to know where your code has troubles, are you able to reproduce the error with other ids?
NerijusNerijus
Performing delete inside the trigger.
I don't know how can I replicate with other ids, the record is not there and I don't know other record ids because they do not exist.
Cheers thanks for your help!