Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I detect when an attachment is related to an account from a Trigger on account ??

Also, I want the trigger to post to chatter that the attachment has been uploaded upon completion.

share|improve this question
user5428, I've taken the liberty to remove some unnecesairy(unrelated) tags. Please try to only use tags closely related to the content of your question, that will help you attract the users with the right knowledge to your question. Posting 2 separate questions also makes it rather harder for anyone to respond, I would suggest you post the 2nd one as a separate question. Also: have you already tried something ? Other users are often more motivated to help if they see you have already made an attempt or some research yourself. – Samuel De Rycke Apr 11 '14 at 19:30

You will need to use a trigger on Attachment for this.

You can create a trigger on Attachment using the Developer console, or the IDE (as well as MavensMate), but NOT using the Setup menu like you would with any other object (unless you do a bit of URL hacking).

Edit (appending Keith C's answer so there is one complete answer rather than two partial ones):

Then to check that it is an Attachment of an Account and not some other object:

for (Attachment a : 
    if (a.ParentId.getSObjectType() == Account.getSObjectType()) 
        // ...
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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