I'm trying to create a function that will transfer attachments in leads to the newly created account. I know there's an option to choose where the attachments go when you click the standard convert button but we have a high volume of conversions per day so we have automated conversion. Once we get an automatic notification of an approved account from our partner, we have a Zapier flow trigger the lead conversion and so as a result, it skips the manual selection of where to transfer the attachments (by default they go to the contact). I created the following function to convert the lead and transfer the attachments to the account:
relatedrecords = zoho.crm.getRelatedRecords("Attachments","Leads",leadid);
convert = zoho.crm.convertLead(leadid);
accID = convert.get("Accounts");
attachid = List();
for each ele in relatedrecords
{
attachmentId = ele.get("id");
attachid.add(attachmentId);
}
for each ele in attachid
{
downloadFile = invokeurl
[
url :"https://www.zohoapis.com/crm/v2/Leads/" + leadid + "/Attachments/" + ele
type :GET
connection:"lead_attach"
];
resp = zoho.crm.attachFile("Accounts",accID,downloadFile);
}
The issue is that the invokeurl function returns an error that the lead is already converted and so it can't access the link to the attachment. I tried the same function without converting the lead and it successfully accesses the attachment URL and so it appears that the URL is no longer accessible once the lead is converted. Any ideas on how I can make this work?
Thanks