You need to sign in to do that
Don't have an account?
Please help to correct the mass clone attachment trigger
Hi,
I am mass cloning the record and for mass cloning the attachment i have written the trigger but its cloning the attachment of first record only and i want to mass clone the attachment with record also.
Can anyone please help me to resolve mu problem .Help will really appriciated.Please find attached my trigger below.What changes needed to do for mass cloning the attachment also.
trigger CopyAttachments on New_Support__c(after insert)
{
List<Id> parentIds=new List<Id>();
Attachment[] attList = [select id, name, body from Attachment where ParentId = :Trigger.new[0].Parent_New_Support__c];
Attachment[] insertAttList = new Attachment[]{};
for(Attachment a: attList)
{
Attachment att = new Attachment(name = a.name, body = a.body, parentid = Trigger.new[0].id);
insertAttList.add(att);
}
if(insertAttList.size() > 0)
{
insert insertAttList;
}
}
Thanks in advance:-)
Are you trying to move all the attachments from New Support to Parent New Support??
Yes i am trying to move all the attachment via record by record basis.
But your query is fetching only the first record. So you will have attachment created only for the first record.
Can you please correct me where i am going wrong in my code can you please provide some changes to work this code which i want.
You need to get all the record ids in a set and then query all the attachments.
You also need to create a map between parent and child.
Then loop through all the attachments and based on the map create attachment for the parent records.
Thanks for your reply.
Can you please have any example which can give me some knowledge to write te code for that because i am very new for this map ,so it would be very helpfull for me.