2

I have an issue where files that have been attached to opportunities are showing up in the parent accounts as well. How do I prevent an attachment associated with an account's opportunity from rolling up to the account?

2 Answers 2

3

There is one way to move the attachments as Files on Opportunity. Please refer to the code below (from one of my class) to get the idea:

public void addAttachment()
{
    attachment.parentId=caseId;
    insert attachment;

    //Adding a Content post
    FeedItem post = new FeedItem();
    post.ParentId = caseId; //eg. Opportunity id, custom object id..
    post.Body = 'Attachment added';
    post.ContentData = attachment.body;
    post.ContentFileName = attachment.Name;
    insert post;
}

This code can be used to run in loops (with DML statement outside loops) for the Opportunities you identify and once done the attachments for the same opportunities can be deleted using code as well.

1
  • Note this code doesn't work after api v35
    – NSjonas
    Aug 30, 2019 at 18:11
1

It doesn't appear that there's a lot you can do to modify the way Attachments are handled by Salesforce. This blog entry by Jeff Douglas recommends creating a new custom object with accompanying triggers and buttons to allow for modification.

Additionally, you could mark the attachments as Private so that only the User who loaded the document would see it.

Though, is there a particular reason why you would want to take away this functionality?

3
  • The problem we've ran into is that parent accounts show 10's or 100's of attachments that were made to opportunities. We want to limit the attachments that show up on accounts to things like trip reports and other information specific to the account. The opportunity attachments aren't necessarily relevant at the account level.
    – Mako212
    Sep 15, 2015 at 17:08
  • That makes sense. You could attach the file to the Opportunity feed instead of loading the file through the Attachments related list. The file will still appear in the Attachments related list on the Opportunity, but won't appear on the Account. Might require a massive moving of current files and a change of company culture. Sep 15, 2015 at 17:24
  • Moving forward that's something to consider, but like you say, it would be a huge and tedious task to move current files.
    – Mako212
    Sep 15, 2015 at 21:00

You must log in to answer this question.

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