1

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
  • 1
    You cannot require a child record on insert. – Adrian Larson Apr 12 '17 at 0:05
1

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.

2
  • 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 Apr 12 '17 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 Apr 12 '17 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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