You need to sign in to do that
Don't have an account?
Swaraj Behera 7
Attachments from lead to opportunity trigger
Hi,
While converting lead to opportunity,i want to attach all the attachments from lead to opportunity.
I have written a trigger for this but its nor firing.Can you please help me on this.
While converting lead to opportunity,i want to attach all the attachments from lead to opportunity.
I have written a trigger for this but its nor firing.Can you please help me on this.
trigger LeadConvert on Lead (after update) { List<Attachment> lstattach=new List<Attachment>(); if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) { System.debug('oppid' + Trigger.new[0].ConvertedOpportunityId); Attachment aa=[Select Id,ParentId from Attachment where ParentId=:Trigger.new[0].ConvertedaccountId]; System.debug('attachment in lead' + aa ); if (Trigger.new[0].ConvertedOpportunityId != null) { for(Attachment a:[Select Id,ParentId from Attachment where ParentId=:Trigger.new[0].ConvertedaccountId]){ a.ParentId=Trigger.new[0].ConvertedOpportunityId; System.debug('parentid' +a.ParentId); lstattach.add(a); } update lstattach; } } }
Thank you for all the replies.
I got the solution.Parent Id is not rewritable so my code was not working.Now i have created a new attachment and inserting it.
Below is the solved code.
Thanks,
Swaraj
All Answers
Use the Before Update context of Trigger, it should work.
Regards,
Akash.
i think we cannot update the attachment parentId and so we need to add the attachment from
Lead to Oppourtunity.
Then delete the Attachment from Lead.
Thanks
D Naveen Rahul.
Refer the below code:
This sample code is not tested but will give you an idea to proceed.
Thank you for all the replies.
I got the solution.Parent Id is not rewritable so my code was not working.Now i have created a new attachment and inserting it.
Below is the solved code.
Thanks,
Swaraj