I have a Web-to-Case form on our community portal for users to submit new cases. I have a trigger that checks to see if the new case has an attachment on it in order to be submitted, basically making the attachment required in order for it to be created for certain types of cases. However. The trigger fires off even when there is an attachment on the new case form. I realize that the case has not yet been created and therefore the trigger applies. Here is a draft of my code:
trigger CreateCaseTrigger on Case (before insert) {
for(Case c:Trigger.New) {
Attachment a = new Attachment();
try {
a = [Select Id, Name from Attachment where ParentId =:c.Id];
}
catch(Exception e) {
a = null;
}
if (a == null)
c.addError('Add an attachment before you close the Case');
}
Any help would be greatly appreciated!