+ Start a Discussion
shashikant pandeyshashikant pandey 

Attachment Cloning from Custom object to Account objet

Hi All,

I have custome object 'PriceReconfirmation__c' and it has notes and attachment related List and also This object having Account Lookup field.
I wanted to clone the attachment from  "PriceReconfirmation__c" attachment to Account lookup record Notes and attachment.

could anyone help me out here. 
Thanks !
shaik murthujavalishaik murthujavali
Hi Shashikant,
Follow the below code, hope it helps.
trigger AttachmentClone on Attachment (after insert) {
    List<Attachment> attachments_List = new List<Attachment>();
    for(Attachment attach :trigger.new)
{
        id recId = attach.ParentId;
    	String objName = recId.getSObjectType().getDescribe().getName();
        If(objName == 'PriceReconfirmation__c')
{
            Attachment newFile = attach.clone();
            newFile.ParentId = attach.Account__c;
            attachments_List.add(newFile);
        }
    }
    
    insert attachments_List;
}

If it works fine please mark as a best answers so that it helps others too.