I am new to Salesforce and trying to write a trigger with the picklist values yes or no. If value 'YES' is selected then trigger should fire and display "an attachment is required", if the value is 'NO' should allow saving the record.

We already have a trigger on Account object which is part of managed package, now can I write another trigger on the same Account object?

  • 1
    You cannot require a child record on insert.
    – Adrian Larson
    Commented Apr 12, 2017 at 0:05

1 Answer 1


Yes, you can write your own trigger on the Account object along side any Managed triggers that are there on the object too.


On insert of an Account record you can check for the value of YES, query for related Attachment records and throw an error when none are found but that is the extent of it.

There will never be an Attachment related to the Account during an insert operation because the Account needs to exist prior to associating the Attachment to it.

You would be better off to skip a query for the attachments and simply prevent the insert of an Account with this picklist having a value of YES. This can be done with a Validation Rule as well as in trigger code.


On update of the Account object your scenario becomes more valuable.

The trigger code during update could inspect the related attachments and ensure that the user had uploaded an Attachment prior to changing the picklist value to YES and saving the Account.

  • Mark thanks for your response, I am trying to do same for custom object as well. I would appreciate if you can paste code here, thanks
    – Rob
    Commented Apr 12, 2017 at 1:45
  • trigger Sandals on currency__c (before insert, before update) { for(currency__c c : Trigger.new){ if (c.customfield__c = 'YES'){ c.currency__c = 'Missing Attachement'; } else if{ c.customfield__c == 'NO'; } insert c; }
    – Rob
    Commented Apr 12, 2017 at 1:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .