You need to sign in to do that
Don't have an account?
Hassan CASSIM
I need help to write the test class of the following code that delete an attachments/files when a checkbox is true on a Case
I'm not developer unfortunately , thanks a lot if you can help.
Here is the code of the trigger that actually working, just need the test class :
trigger DeleteContentDocumentLink on Case (Before Update,After Update, Before Delete) {
public Set<Id> CaseSetId = new Set<Id>();
List<Case> csToUpdt = new List<Case>();
if(Trigger.isAfter && Trigger.isUpdate){
for(Case cs:Trigger.New){
if(cs.TECH_DeleteFiles__c== True){
CaseSetId.add(cs.Id);
}
}
If(CaseSetId.size()>0){
List<ContentDocumentLink> casAttmtList = [SELECT ContentDocumentId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case WHERE TECH_DeleteFiles__c = TRUE ) and LinkedEntity.Type='Case'];
Integer count=0;
for (ContentDocumentLink x : casAttmtList) {
List<ContentDocument> casFiles = [SELECT Title FROM ContentDocument WHERE Id = :casAttmtList[count].ContentDocumentId ];
delete casFiles;
count++;
}
}
}}
Thanks a lot
Here is the code of the trigger that actually working, just need the test class :
trigger DeleteContentDocumentLink on Case (Before Update,After Update, Before Delete) {
public Set<Id> CaseSetId = new Set<Id>();
List<Case> csToUpdt = new List<Case>();
if(Trigger.isAfter && Trigger.isUpdate){
for(Case cs:Trigger.New){
if(cs.TECH_DeleteFiles__c== True){
CaseSetId.add(cs.Id);
}
}
If(CaseSetId.size()>0){
List<ContentDocumentLink> casAttmtList = [SELECT ContentDocumentId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case WHERE TECH_DeleteFiles__c = TRUE ) and LinkedEntity.Type='Case'];
Integer count=0;
for (ContentDocumentLink x : casAttmtList) {
List<ContentDocument> casFiles = [SELECT Title FROM ContentDocument WHERE Id = :casAttmtList[count].ContentDocumentId ];
delete casFiles;
count++;
}
}
}}
Thanks a lot
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
Working so well , thanks a lot you are the best !
Hassan