You need to sign in to do that
Don't have an account?

Creating test class for Attachment Trigger
Hello,
I am new to APEX and I created a trigger on Attachments. My goal is to set the Attachment to Private for a specific object and the file ends with .xls. It works perfectly fine but I am having creating test class for it and I can't deploy it to production. The code is below, can someone help me build a test class for it?
Any assistance is greatly appreciated. Thanks
I am new to APEX and I created a trigger on Attachments. My goal is to set the Attachment to Private for a specific object and the file ends with .xls. It works perfectly fine but I am having creating test class for it and I can't deploy it to production. The code is below, can someone help me build a test class for it?
trigger SetAttachmentPrivate on Attachment (before insert) { string s; for(Attachment record:Trigger.new) { if((String.valueOf(record.parentId)).startswith('001') && (String.valueOf(record.Name)).endswith('.xls')) record.IsPrivate = TRUE; } }
Any assistance is greatly appreciated. Thanks
Please try code like below : Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.
Thank you for your help.
Actually, I have the same exact code you have right there but I'm only getting 75% code coverage. When I try to check with developer console, I'm getting with a red mark on "attach.IsPrivate = TRUE;".
Is there a possible way to create a code on that line?
Thanks.