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

Duplicate in list. Any suggestions?

Hi All,

i am geting this error when i attch an image to master object (in file and attchments) and the detail object have records.i am also updating master object when a new detail record is added and approved. 
it seems that adding an image trigers the loop.

Error: Apex trigger trgOrphanImage caused an unexpected exception, contact your administrator: trgOrphanImage: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a0H2000000A5UtqEAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgAnnualProgressReportIns: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: a0A2000000KkOr2EAF Class.AnnualReportUpdBiodata.updBiodata: line 96, column 1 Trigger.trgAnnualProgressReportIns: line 49, column 1: []: Trigger.trgOrphanImage: line 59, column 1

Ravikant kediaRavikant kedia
HI ArrgHunter,
                     If list have a duplicate element then you can use set instead of list set works just like list but it have a diffrence that it doesn't store duplicate value.
Yoganand GadekarYoganand Gadekar
If you are doing a dml on list and if list has duplicate records then you will get this error. Make sure your list has records only once.
for example you can use if statement to do this,
For apex basics you can visit this: