function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DaveT.ax1572DaveT.ax1572 

Lead Convert Trigger to not create new account but use and existing account.

I am using a trigger to fire on my web to lead form from a specific leadsource to create a contact.  Is there a way for it to not create an account but add the contact to and existing account?  here is my code.  what I am thinking is that I would create an account trigger to fire on the leadsource and add the contact to the account correct??

 

here is the lead trigger:

trigger KYR_LeadConvert on Lead (after insert,after update) {
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.LeadSource == 'youknowit')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.id);
        lc.setopportunityName(myLead.Refersite__c);
        lc.convertedStatus = 'Qualified';
        
        //Database.ConvertLead(lc,true);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
        }
}

 

thank you for the help;)

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu

try,
lc.setAccountId('001xxxxxx');
then you can convert your Lead to a Contact of an existing Account.

All Answers

Jia HuJia Hu

try,
lc.setAccountId('001xxxxxx');
then you can convert your Lead to a Contact of an existing Account.

This was selected as the best answer
DaveT.ax1572DaveT.ax1572

Jia,

 

Thank you are awesome .... works great !!!