You need to sign in to do that
Don't have an account?
kladizkov
Changing the lead to "Converted" using Apex Trigger
Hi,
I had a requirement to automatically insert/update Contact when a new lead comes in. So, I wrote a before update trigger. Everything worked great, but I need the lead to get into "Converted" state once I have the trigger finish its job. Is there any way to mark it as Converted inside the trigger code?
Ibascle,
In the code above, the LeadConvert object has a method called "setOwnerId"... that is where you specify the ID of one of the users in your org, prior to calling LeadConvert.
--k
All Answers
Yes:
http://www.salesforce.com/us/developer/docs/apexcode/index.htm
Database Method Example
Basic Steps for Converting Leads
Converting leads involves the following basic steps:
select id, name from account where name='CompanyNameOfLeadBeingMerged'
Hi,
The code below converts the lead and works fine for me.
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(l.id);
LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
But, is it possible to set the status of the lead to "converted" without actually converting it. This is because, I create an custom object from the lead. After creating the custom object, I don't want the lead to be "convertable" but should be available in lead reports.
I tried skipping the convertLead() call, but it didn't work for me. Any idea, how to accomplish this?
You could have a dummy contact & account that you merge all leads into when converting to avoid dupes in the system. Also, you could delete the newly created contact & account with a trigger if that's easier.
I don't believe you can simply convert without creating any objects or merging into others however. A 3rd option would be a custom field you use for reporting in replacement of the IsConverted field.
\"Optionally, when converting leads owned by a queue, the owner must be specified. This is because accounts and contacts cannot be owned by a queue. Even if you are specifying an existing account or contact, you must still specify an owner."
i am having that very problem, how do i specify an owner?
Ibascle,
In the code above, the LeadConvert object has a method called "setOwnerId"... that is where you specify the ID of one of the users in your org, prior to calling LeadConvert.
--k