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
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.