Yes, you can write your own trigger on the Account object along side any Managed triggers that are there on the object too.
Insert
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.
Update
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
.