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
satyamsatyam 

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:-)

PrakashbPrakashb

Are you trying to move all the attachments from New Support to Parent New Support??

satyamsatyam

Yes i am trying to move all the attachment  via record by record basis.

PrakashbPrakashb

But your query is fetching only the first record. So you will have attachment created only for the first record.

satyamsatyam

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.

 

 

PrakashbPrakashb

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. 

satyamsatyam

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.