+ Start a Discussion
Deepak G 9Deepak G 9 

how we can move notes and attachments from one account to another account

HI All,
how we can move notes and attachments from one account to another account through code?
Kindly help me on this.

Regards,
Deepak
Best Answer chosen by Deepak G 9
Amit Singh 1Amit Singh 1
Hello Deepak,

You can move Notes and Attachments from One Account to another Account using clone method. The example code will look like below code.
 
List<Attachment> attList = [Select Id, Name, Body FROM Attachment Where ParentId='Your Old Account Id'];
List<Attachment> clonedAttachmentList = new List<Attachment>();
For(Attachment a : attList){
    Attachment att = new Attachment();
    att = a.clone(false, false, false, false);
    att.ParentId = 'Your New Account Id';
clonedAttachmentList.add(att);
}
If(clonedAttachmentList!=null && clonedAttachmentList.size()>0) insert clonedAttachmentList;
If(attList!=null && attList.size()>0) delete attList; // if you want to delete.

Also, visit below link for clone method.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

Let me know the outcomes.
Thanks,
Amit Singh

All Answers

Amit Singh 1Amit Singh 1
Hello Deepak,

You can move Notes and Attachments from One Account to another Account using clone method. The example code will look like below code.
 
List<Attachment> attList = [Select Id, Name, Body FROM Attachment Where ParentId='Your Old Account Id'];
List<Attachment> clonedAttachmentList = new List<Attachment>();
For(Attachment a : attList){
    Attachment att = new Attachment();
    att = a.clone(false, false, false, false);
    att.ParentId = 'Your New Account Id';
clonedAttachmentList.add(att);
}
If(clonedAttachmentList!=null && clonedAttachmentList.size()>0) insert clonedAttachmentList;
If(attList!=null && attList.size()>0) delete attList; // if you want to delete.

Also, visit below link for clone method.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

Let me know the outcomes.
Thanks,
Amit Singh
This was selected as the best answer
UDAYA TEJA PASUPULETIUDAYA TEJA PASUPULETI
Thanks you so much Amit for sharing the information. Can we do sam logic for Notes transfer as well.