You need to sign in to do that
Don't have an account?
Convert Lead To Existing Account & Contact
Hello,
I am looking to develop a trigger that will fire when a Lead is created. It will need to convert the lead to an Account and Contact (no Opportunity) but also search to see if there are existing Accounts/Contacts that it would be merged with. The code I have below converts the leads, but it doesn't check for existing Accounts or Contacts. Is there a way to modify it so that it will merge the Lead into any existing Accounts/Contacts or create new Accounts/Contacts if no existing ones are found?
trigger LeadConvert2 on Lead (after update) {
List<Account> accList = new List<Account>();
List<Contact> conList = new List<Contact>();
List<Opportunity> oppList = new List<Opportunity>();
//Bulkified
for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion
{
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
Account acc = new Account(id=lcr.AccountId);
accList.add(acc);
Contact con = new Contact(id=lcr.ContactId);
conList.add(con);
Opportunity opp = new Opportunity(id=lcr.OpportunityId);
oppList.add(opp);
}
}
update accList;
update conList;
update oppList;
}
Just closing this thread. After much searching and even checking out some Apps, it doesn't look like a good solutions exists for automatically converting leads, which is proably a best practice but does not help our project. Thanks for your assistance.
All Answers
JN22 - did you look at this? http://salesforce.stackexchange.com/questions/4209/can-i-programmatically-merge-leads-to-existing-accounts
Just closing this thread. After much searching and even checking out some Apps, it doesn't look like a good solutions exists for automatically converting leads, which is proably a best practice but does not help our project. Thanks for your assistance.