You need to sign in to do that
Don't have an account?
tomoko_o
trigger to mark attachment private
Hi,
I need some help on creating trigger for attachment for case and workorder object.
I found the code to make all attachment as private before insert, but how can I make it work only for case and workordre object?
Which field can tell what object the attachment is being attached to?
Thank you,
trigger PrivateAttachment on Attachment (before insert) { for(Attachment record:Trigger.new) { record.IsPrivate = TRUE; } }
Try this
trigger PrivateAttachment on Attachment (before insert) {
string s;
for(Attachment record:Trigger.new) {
if((String.valueOf(reocrd.parentId)).startswith('500') || (String.valueOf(reocrd.parentId)).startswith('XXX')) //xxx would be your custom object prefix
record.IsPrivate = TRUE;
}
}
All Answers
trigger PrivateAttachment on Attachment (before insert) {
for(Attachment record:Trigger.new) {
if((reocrd.parentId).startswith('500') || (reocrd.parentId).startswith('XXX')) //xxx would be your custom object prefix
record.IsPrivate = TRUE;
}
}
Thank you for your reply.
I tried the code but got error saying "Error: Compile Error: Method does not exist ro incorrect signature: [id].Startswith(String) at line 3 column27"
Anything else I can try?
Try this
trigger PrivateAttachment on Attachment (before insert) {
string s;
for(Attachment record:Trigger.new) {
if((String.valueOf(reocrd.parentId)).startswith('500') || (String.valueOf(reocrd.parentId)).startswith('XXX')) //xxx would be your custom object prefix
record.IsPrivate = TRUE;
}
}
Thank you!!
That was it.