+ Start a Discussion
BrittanyBrittany 

Lead Assignment Rules : New lead conversion when a contact already exists

Hi everyone,

 

I am hoping that someone could help me out and I apologize if I posted this in the wrong section. I am new to the developer force. My company has the Enterprise version of SFDC.

 

I am trying to find a way to have new leads that come in to SFDC convert automatically if there is an existing contact or if the leads company is an existing account. I don't know Apex code all that well so anything would help.

 

Thank you!

Ispita_NavatarIspita_Navatar

Hi,

            You can implement this functioanlity in apex code through convertlead operation in database method.

                                    Convertlead operation in database method converts the lead into account,contact and opportunity

                                    Follow the sample code it would help you in achieving your objective.

                                    Lead myLead = new Lead(lastname = 'Fry', company='Fry And Sons');

                                                insert myLead;

                                                Database.LeadConvert lc = new database.LeadConvert();

                                                lc.setLeadId(myLead.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());

                                               

                                                for more information you can visit apex guide for summer'11 for convert lead operation.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

WiznoWizno

Hi,

 

I'm currently trying this snippet in a trigger and when I make a lead, it says that it was converted after I save it. However, when I check my Account and Contacts objects, there are no new records and the lead gets deleted.

 

Only difference between my code and what is posted is that I am running it through a loop on a trigger on the lead object after insert.

 

Been scratching my head all day trying to figure out what I'm doing wrong after looking at 4-5 different tutorials that are essentially the same.