function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ANITHA BEEMU 2ANITHA BEEMU 2 

HI,can anyone have a idea on this..is there any way to have opportunities documents(files ) to rollup with accounts..pl s do help..

Raj VakatiRaj Vakati
You need to write the trigger on contect document .. 

Check the Parent Id of contect document  if its started with 006 then create a new contect document  and assign it to the account 
ANITHA BEEMU 2ANITHA BEEMU 2
Hi Thank you for the response..ya its starting with 006 only..i am admin,can you pls help me in writting trigger..thank you
ANITHA BEEMU 2ANITHA BEEMU 2
Hi i tired this code but getting error..can anyone help:

Trigger CopyopportunityAttachtoAccount on Attachment (after insert)     
{
    set<id> Oppids=new set<id>();
    Map<id, attachment> OpportunityAttachments = new Map<id, attachment>();
    Map<id, Opportunity> OpportunitiesWithAccount = new Map<id, Opportunity>();
    for(attachment an:trigger.new)
    {
        if(an.ParentId.getSobjectType() == Opportunity.SobjectType) OpportunityAttachments.put(an.ParentId, an);
            //Oppids.add(an.ParentId);
    }
    // not required, as using soql 
    // list<Opportunity> OppAccmap =new list<Opportunity>([Select Account.id,Account.name from Opportunity where Id In:Oppids]);

    list<attachment> accatt=new list<attachment>();
    //for(Opportunity Ot:OppAccmap){
    // read "Explanation" why I have replaced Soql For loop with your approach
    if (OpportunityAttachments.keySet().size() > 0) // Read "Explanation" why this check is introduced.
    {
        OpportunitiesWithAccount = new Map<Id, Opportunity>([SELECT Id, Account.id FROM Opportunity WHERE Id IN :OpportunityAttachments.keySet()]);
        // for (attachment am :[select id, name,parentId, body from Attachment where ParentId in :Oppids]) // soql inside for loop is bad, bad thing.
        for (attachment am: OpportunityAttachments.values() ) 
        {
            if (OpportunitiesWithAccount.containsKey(am.ParentId) )
            {
                Attachment newFile = New Attachment(Name = am.name, body = am.body, ParentId=OpportunitiesWithAccount(am.ParentId);
                accatt.add(newFile);
            }
        }
    }
    insert accatt;
}

GETTING ERROE OVER HERE:

Attachment newFile = New Attachment(Name = am.name, body = am.body, ParentId=OpportunitiesWithAccount(am.ParentId);
                accatt.add(newFile);

AND Incorrect SObject type ..PLS DO HELP