You need to sign in to do that
Don't have an account?
Please help to correct the mass clone record with 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:-)
It's only cloning the first New_Supports attachments because of the where condition in your soql:
"where ParentId = :Trigger.new[0].Parent_New_Support__c"
That [0] means you're only checking for the 1st element of the list(arrays and lists start at 0 index).
PS: this was written fast and dirty in a generic text-editor. Sorry for typos and such, in advance
Adi