• Yuri Aldanov
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi! I finally got this simple Apex Trigger working in Sandbox:
trigger restrictFileDeletion on ContentDocument (before delete) {
    String profileName=[SELECT id,Name FROM Profile WHERE Id =:UserInfo.getProfileId()].Name; 
       for (ContentDocument cd : Trigger.old){     
        If(profileName=='ALS Community v6'){
            cd.addError('You cannot delete this record!');
        }
    }
}

Then I went to deploy in production and I received this error "Code Coverage Failure The following triggers have 0% code coverage.  Each trigger must have at least 1% code coverage.restrictFileDeletion.

I have read all related threads and Trailhead, and I'm still stuck on how to write a test class to get this to deploy in production. I would be so appreciate of any help to get this working. I was so excited to get this working in Sandbox, now I've wasted hours, and it's still not working in production. Thanks in advance!!