Open andykallio opened 7 years ago
Thanks @andykallio for the screen shot and debug log. I'll see what I can discover.
I have been playing around with this some more and it looks like it has to with the method for recently viewed files. I'm getting the duplicate Id error at line 171 of ChatterAddFilestoRecordsController when I execute the test class, which is this:
Map<ID, RecentlyViewed> recentlyViewedMap = new Map<ID, RecentlyViewed>([ SELECT id FROM RecentlyViewed WHERE type = 'ContentDocument' ]);
I changed to this based on a post I found on stackexhange, and the test class now succeeds.
List<RecentlyViewed> rvs = [SELECT id FROM RecentlyViewed WHERE type = 'ContentDocument']; Map<ID, RecentlyViewed> recentlyViewedMap = new Map<ID, RecentlyViewed>(); recentlyViewedMap.putAll(rvs);
This also eliminates the error pop-up! You are talking to an admin here, though. So, I will let you do what you want with that code.
@andykallio What results do you get if you run the query in Developer Console and Data Loader?
Does this happen for other users?
Seems like it'd be a bug if the SOQL query is returning the same record ID twice. Are any of the documents that you've recently viewed external files like to SharePoint or Google or Box?
The query runs successfully for me in the dev console. None of the results would be external files. I agree that it seems buggy. It didn't take long to find that stackexchange post by googling that error message.
Thanks for the info and reference link to stackexchange. I guess my Recently Viewed query must be returning the same document twice in some scenarios. I'll look to make the adjustment as recommended, thanks!
I came across this error when my System Admin tried to deploy changesets. The unit test ran fine under my login. After I updated the code as listed above all worked fine for the sysadmin.
I receive an error pop-up after clicking the 'Attach Files' button. The error message in the pop-up is 'Row with duplicate Id at index: 1'.
However, I can close the pop-up and continue on to successfully attach files.
The pop-up has appeared in every scenario that I have tried:
multiple Accounts selected
single Account selected
multiple custom object selected
single custom object selected
Here is an excerpt from a debug log: 13:33:05.9 (24940788)|VARIABLE_SCOPE_BEGIN|[201]|e|Exception|true|false 13:33:05.9 (25097275)|VARIABLE_ASSIGNMENT|[201]|e|"common.apex.runtime.impl.ExecutionException: Row with duplicate Id at index: 1"|0x3376c42f 13:33:05.9 (25107992)|STATEMENT_EXECUTE|[201] 13:33:05.9 (25109859)|STATEMENT_EXECUTE|[204] 13:33:05.9 (25308197)|SYSTEM_METHOD_ENTRY|[204]|System.ListException.getMessage() 13:33:05.9 (25352995)|HEAP_ALLOCATE|[204]|Bytes:33 13:33:05.9 (25364594)|SYSTEM_METHOD_EXIT|[204]|System.ListException.getMessage() 13:33:05.9 (25369923)|HEAP_ALLOCATE|[204]|Bytes:3 13:33:05.9 (25380150)|SYSTEM_METHOD_ENTRY|[204]|System.ListException.getStackTraceString() 13:33:05.9 (25393831)|HEAP_ALLOCATE|[204]|Bytes:83 13:33:05.9 (25398423)|SYSTEM_METHOD_EXIT|[204]|System.ListException.getStackTraceString() 13:33:05.9 (25412743)|HEAP_ALLOCATE|[204]|Bytes:119 13:33:05.9 (25432276)|SYSTEM_METHOD_ENTRY|[204]|System.debug(APEX_OBJECT, ANY) 13:33:05.9 (25446527)|USER_DEBUG|[204]|ERROR|Row with duplicate Id at index: 1 : Class.ChatterAddFilesToRecordsController.getRecentlyViewedFiles: line 171, column 1 13:33:05.9 (25457798)|SYSTEM_METHOD_EXIT|[204]|System.debug(APEX_OBJECT, ANY) 13:33:05.9 (25464622)|STATEMENT_EXECUTE|[205] 13:33:05.9 (25478368)|SYSTEM_METHOD_ENTRY|[205]|System.ListException.getMessage() 13:33:05.9 (25493558)|HEAP_ALLOCATE|[205]|Bytes:33 13:33:05.9 (25503637)|SYSTEM_METHOD_EXIT|[205]|System.ListException.getMessage() 13:33:05.9 (25634099)|FATAL_ERROR|System.AuraHandledException: Script-thrown exception
Class.ChatterAddFilesToRecordsController.getRecentlyViewedFiles: line 205, column 1 13:33:05.9 (25647258)|FATAL_ERROR|System.AuraHandledException: Script-thrown exception