I have some leads that come in with Not Provided in the Company field. This is due to the company field not being required. Not everyone who fills out our form is a company, hence the reason for not making the field required.
This has caused another issue in conversion. We have had leads converted with the text Not Provided instead of the residential customer's name. This causes accounts to be created with Not Provided in desk.
I have created a workflow rule to look for leads with Not Provided in the Company field. I am working on creating a function that updates the company field to the first and last name of the lead.
I have been working with chat gpt to help me develop the code. There are items commented out as I am trying new options.
// Retrieve the lead details+
//leadId = leadId;
//leadIdLong = input.leadId.toLong();
leadIdLong = input.leadId.toLong();
leadDetails = zoho.crm.getRecordById("Leads",leadIdLong);
// Make sure input.leadId is the correct way to access the lead ID passed to the function
// Check if the retrieved data is not null and correctly converted
if(leadIdLong != null)
{
// Extract relevant fields
leadDetails = zoho.crm.getRecordById("Leads",leadIdLong);
// Use leadIdLong here for the correct ID
if(leadDetails != null)
{
leadCompany = leadDetails.get("Company");
leadfn = leadDetails.get("First_Name");
leadln = leadDetails.get("Last_Name");
if(leadCompany != null && leadfn != null && leadln != null)
{
cat = leadfn.concat(" ").concat(leadln);
updateMap = Map();
updateMap.put("Company",cat);
response = zoho.crm.updateRecord("Leads",leadIdLong,updateMap);
// Use leadIdLong here
info response;
}
else
{
info "One or more required fields (Company, First_Name, or Last_Name) are missing.";
}
}
else
{
info "No lead details found for the given leadId.";
}
}
else
{
info "Invalid leadId format. Please provide a valid numeric leadId.";
}
When I look at the results of the workflow this is the error I am currently receiving:
Unable to cast the 'TEXT' value into a 'Long' value because the input is in an invalid formatat lineNumber 6
What needs to be changed in my code to get the function to work? Can I execute this function with less code?
If so, what is the streamlined code?