You need to sign in to do that
Don't have an account?
Manuel Briceño 3
Limiting to number of attachments in a record to 1
Good morning folks,
I was wondering if its is possible to have a trigger on attachment whereas it would check if the record already has an attached file, and if so it would give an error and would not allow anymore files to be attached on said record.
And if the latter is indeed possible what should the trigger be counting? Attachments or Contentdocument?
Thanks in advanced for the help.
I was wondering if its is possible to have a trigger on attachment whereas it would check if the record already has an attached file, and if so it would give an error and would not allow anymore files to be attached on said record.
And if the latter is indeed possible what should the trigger be counting? Attachments or Contentdocument?
Thanks in advanced for the help.
You will have to write an Apex Trigger(After Insert) on the Attachment object, that would see if the Attachment getting created is the desired one and also is it getting attached to the Opportunity record. If so, you can then update may be a Checkbox field on the Opportunity record. Then you can make use of this very Checkbox in the Entry Criteria. Note that you may also have to build another Apex Trigger(Before Delete) in which you will un-check the Checboxif in case a User deleted the Attachment. Also, another Apex Trigger(After Undelete) to check the Checkbox again if the User undeletes it from Recycle Bin. So you may need some considerable Development Effort to get this done.
Thanks,
SEKAR RAJ
You can write a before insert trigger on Attachment and check whether the ParentId of the newly inserted record contains an Attachment or not. Based on the results you can throw error on the Attachment. Please find the trigger code below:
The error will be shown when you click on the Attach button as shown below:
Thanks,
Abhishek Bansal.