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_DEVELOPER_NAME while the Document already deleted



I did some code to  insert Document thru apex and successfully work. For Document Name and Developer Name, I generate it dynamically  by concatenate it with some variables and object name. Something like below

docName= 'XX_'+autoNumber+'_'+accountName+'_'+ accountCountry;
document.Name =docName;
upsert document;



The issue is, I manually delete the Document  and run my apex code to insert  back the Document but I face this error:


First exception on row 0; first error: DUPLICATE_DEVELOPER_NAME, This Document Unique Name already exists or has been previously used.  Please choose a different name


Well,I do not understand why it prompt me this  error as I already deleted the Document.I already check the Document and it could not be found.


Here the method how I check the Document, unfortunately it return nothing.I also remove isDeleted and still it return nothing.If it return nothing, the duplicate issue should not happen at the first place as the Document is not there.Or is it different case for Document.


SELECT Name, DeveloperName, Type, IsDeleted FROM Document where DeveloperName like 'XX_100%' and isDeleted=true




Just have a look at the error message :


"This Document Unique Name already exists or has been previously used.  Please choose a different name"




So that means, even the Document being deleted, it still cannot be duplicated? Just thinking how to avoid this Exception for Document insertion thru Apex controller.