You need to sign in to do that
Don't have an account?
Ivan Winzer
converting lead to person account
So we have a lead convert class that is now throwing a Cannot Insert Update error. It says that is is Unable to create/Update field: Name. Below is a part of the code that i believe is the issue but im not 100% sure on how to tweak it so that it doesnt try to place first and last name into the name field but doesnt break the code.
Any help or thoughts is grately appreciated.
Ivan
if(leadsToConvert.size()>0){ List<Database.LeadConvertResult> results = Database.convertLead( leadsToConvert, false); List<Account> accountsToUpdate = new List<Account>(); for(Database.LeadConvertResult result : results){ lead l = leadIdMap.get(result.getLeadId()); if(result.success && result.getAccountId()!=null){ String name = ((l.FirstName!=null)?l.FirstName+' '+l.LastName:l.LastName); if(name!=null){ accountsToUpdate.add(new Account(Id=result.getAccountId(), name = name)); } } else{ for(Database.Error error : result.getErrors()){ l.addError(error.getMessage()); } } }
Any help or thoughts is grately appreciated.
Ivan
Hi Ivan,
Can you try with this below sample code:-
TriggerOnConvertLeads Trigger:-
ConvertLeads class:-
Please mark it as Best Answer so that it can help others in the future.
Regards,
Priya Ranjan
All Answers
Hi Ivan,
Can you try with this below sample code:-
TriggerOnConvertLeads Trigger:-
ConvertLeads class:-
Please mark it as Best Answer so that it can help others in the future.
Regards,
Priya Ranjan
Hi Ivan Winzer
I am Sharing a link Please check it. it will help you
Please mark it as Best Answer so that it can help others in the future.
Thanks
Suraj Tripathi