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
Soundar Rajan PonpandiSoundar Rajan Ponpandi 

Change this code for list of records update

Hi,

Can you please help me to update with bulkify of this coding.
 
ContentDocumentLink exFile=[SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType FROM ContentDocumentLink WHERE LinkedEntityId =: request.get(0).id];
                ContentDocumentLink newFile= exFile.clone();
                newFile.LinkedEntityId = con.id;
                
                insert newFile;
                delete exFile;

Thanks in Advance ,
Soundar.
Best Answer chosen by Soundar Rajan Ponpandi
Abhishek BansalAbhishek Bansal
Hi Soundar,

Please find the code below:
List<ContentDocumentLink> insertList = new List<ContentDocumentLink>();
List<ContentDocumentLink> deleteList = new List<ContentDocumentLink>();
ContentDocumentLink newFile;
for(ContentDocumentLink exFile : [SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType FROM ContentDocumentLink WHERE LinkedEntityId =: request.get(0).id]){
	newFile = new ContentDocumentLink();
	newFile= exFile.clone();
	newFile.LinkedEntityId = con.id;
    insertList.add(newFile);
	deleteList.add(exFile);
}
if(insertList.size() > 0) {
	insert insertList;
}
if(deleteList.size() > 0) {
	delete deleteList;
}

Please take care of the syntax errors and let me know if you need any other help on this.

Thanks,
Abhishek Bansal.

All Answers

Abhishek BansalAbhishek Bansal
Hi Soundar,

Please find the code below:
List<ContentDocumentLink> insertList = new List<ContentDocumentLink>();
List<ContentDocumentLink> deleteList = new List<ContentDocumentLink>();
ContentDocumentLink newFile;
for(ContentDocumentLink exFile : [SELECT Id, LinkedEntityId, ContentDocumentId, Visibility, IsDeleted, ShareType FROM ContentDocumentLink WHERE LinkedEntityId =: request.get(0).id]){
	newFile = new ContentDocumentLink();
	newFile= exFile.clone();
	newFile.LinkedEntityId = con.id;
    insertList.add(newFile);
	deleteList.add(exFile);
}
if(insertList.size() > 0) {
	insert insertList;
}
if(deleteList.size() > 0) {
	delete deleteList;
}

Please take care of the syntax errors and let me know if you need any other help on this.

Thanks,
Abhishek Bansal.
This was selected as the best answer
Soundar Rajan PonpandiSoundar Rajan Ponpandi
Thanks Abhishek,

This code is working perfectly.

Regards,
Soundar.