You need to sign in to do that
Don't have an account?
Calculating attachment size in tigger
Hi,
i am trying to limit the attachment size to 2 MB through a trigger.it seems like not calculating correct size. i want to limit the users so that they only able to upload files less than 2 MB in size.
i am trying with following code
trigger trgCheckFileSize on Attachment (after insert) {
list<Attachment> att = new List<Attachment>();
for (Attachment a : Trigger.new) { att.add(a); }
integer sizecheck = att.get(0).body.size();
if (sizecheck > 2097152){
att.get(0).addError('max size 1 Mb: you are trying file size ' + String.Valueof(sizecheck)); }
}
any idea why its not calculating the correct size.
ps: for file size 8kb, i am getting body size 8098.
thanks,
ok guys, i have figured out what was wrong.
instead of using (after insert) i used (before insert) and it worked.
well done Me...