I need to Prevent inserting attachment if parent record's status is "Closed". I have tried with before insert where i couldn't get parentid so it is not working. Any directions/suggestions will greatly appreciated.

  • 1
  • Hi Renato, Similar to that question only. but as Frank said in the question, Not able to prevent attachment while inserting. I have tried with that code. The problem is we cannot get Parentid before insert. How to do that? – chris Dec 21 '19 at 13:47
  • What do you mean? For content documents the related entity Id is on the ContentDocumentLink entity, in the LinkedEntityId field. – Renato Oliveira Dec 21 '19 at 14:31
  • Ok should i write Trigger on ContentDocumentLink? I am wring trigger on contentDocument Object. – chris Dec 21 '19 at 14:35

Create a Trigger on ContentDocumentLink object which is related to your Parent record using LinkedEntityId field. You may try to use addError method on SObject to prevent DML operation from occurring, but I'm not sure other records (ContentDocument and ContentVersion) won't be created. If they will, you may throw a custom exception with a meaningful message.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.