I am able to set a lead status field of the lead object to a certain value form a picklist using a trigger with the before insert argument BUT I get an error when use the following:

lead.IsConverted = TRUE;

I get the following error message: Cannot insert a converted lead (Related field: Converted)

here is my trigger:

trigger triggerDoSomething on Lead(before insert){

map<string,list<ObjectB>> BObjMap = new map<string,list<ObjectB>>();
for(ObjectB b : [Select Id, Name, fieldZ From ObjectB]){
    if(BObjMap.get(b.fieldZ) == null){
        BObjMap.put(b.fieldZ, new list<ObjectB>());

for(Lead lead : trigger.new){
        //lead.status = 'Converted';
        lead.isConverted = TRUE;


1 Answer 1


I believe you'll have to use the lead conversion process to mark a lead as converted. Something like this:

Database.LeadConvert lc;
lc = new database.LeadConvert();
List<Database.LeadConvertResult> leadConversionResults = Database.convertLead( leadConversions );
  • Thanks Kevin, I've had a look through that, would you mind stepping through it with me as I have some questions such as: are setLeadId and setConvertedStatus methods or properties of the new database "LeadConvert"? What is 'leadConversions' I don't see it declared previously? What does List do? And where is the best source for me to read up on all this? Many thanks.
    – Bartley
    Commented Oct 3, 2013 at 10:50
  • 1
    Going to post a few comments here. One per topic here. Starting with most general: List<type> varName = ... is the way you create a List variable, which is similar to an array. The type of data stored in the list is defined in the < >'s You can learn more about lists here: salesforce.com/us/developer/docs/apexcode/…
    – Kevin P
    Commented Oct 3, 2013 at 10:53
  • 1
    setLeadId() and setConvertedStatus() are both instance methods on the leadConvert object created on line 2 above. You can read more about the leadConversion object, and it's instance methods here: salesforce.com/us/developer/docs/apexcode/…
    – Kevin P
    Commented Oct 3, 2013 at 10:56
  • Sorry about the lack of leadConversion definition. leadConversion is, in this case, defined as: List<Database.LeadConvert> leadConversions = new List<Database.LeadConvert>(); the code i showed you here was extracted from a project of mine, and in that project I was converting many leads in one pass by putting lines 2-5 in a loop looping over lead objects.
    – Kevin P
    Commented Oct 3, 2013 at 11:00
  • OK that's great, one question: is it wrong or incorrect to just set the lead.IsConverted to TRUE without actually converting the lead or putting the lead through the lead conversion process as you have outlined above (I have a need for that in the case where a list of leads I am upserting will need to be set to converted if they already exist as a contact)?
    – Bartley
    Commented Oct 3, 2013 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .