You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Trigger on Content Version for 'before delete' not working
Hello, I build a trigger on ContentVersion that should block deletation of FILES when they have "Geschäftsbrief" in "Dokumentenklasse" - picklist. Sadly the error does not occure when I delete a file with this field :(
Please correct my code:
Please correct my code:
trigger ContentVersionTrigger on ContentVersion (before delete) {
set<Id> contentId = new set<Id>();
if(trigger.IsDelete){
for(ContentVersion con : Trigger.old){
contentId.add(con.Id);
}
List<Attachment> at=[select name,body,contentType from Attachment where parentid in: contentId];
for(ContentVersion con : Trigger.old){
if(con.Dokumentenklasse__c =='Geschäftsbrief'){
if(at.size()>0){
con.addError('You cant delete the file');
}
}
}
}
}
This is the limitation in salesforce You can't use before or after delete triggers with the ContentVersion object.
Check below link:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_ignoring_operations.htm
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
Do you have an idea what to do now?
https://developer.salesforce.com/forums/?id=9060G0000005XgBQAU
https://salesforce.stackexchange.com/questions/136971/how-to-delete-document-in-content-version
https://developer.salesforce.com/forums?id=9062I000000DLvCQAW
Did you try this .