0
votes

I'm sure this is a common task that people need to accomplish in Salesforce, but I can't for the life of my figure out a good way to do it using the Salesforce Data Import Wizard. I simply need to bulk convert a bunch of Leads to Contacts. I can export my lead data and then reimport it as contacts, but then how do I update all of the old leads and mark them as converted? There is a field in Salesforce called "IsConverted", but it's not an option in the list of mappable fields in the import wizard. What is the best way to accomplish this task of bulk converting leads to contacts?

2

2 Answers

0
votes

The IsConverted field is system controlled, you cannot modify it. Converting leads cannot be done via a data import. There is an Apex method and API call that can be used to convert Leads, but a simple update wont work.

You can try apps on the AppExchange that have code prewritten for you.

0
votes

A straight forward approach you can take for this is a simple trigger. You'll need to add a boolean field on the lead with a name like "API Convert". The purpose of this field will be to trigger the conversion of a lead when updated to true. This will allow you to be able to update leads in a data loader by just marking API_Convert__c = true.

Example of the bulkified trigger borrowed from Salesforce Developer community, with an update to add this field as a dependency.

trigger AutoConvert on Lead (after update) {
    list<Lead> LeadsToConvert = new list<Lead>();
    for(Lead myLead: Trigger.new){
      if(!myLead.isConverted && myLead.API_Convert__c == true)
        LeadsToConvert.add(myLead);
    }

    list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
    for(Lead myLead : LeadsToConvert){
      Database.LeadConvert lc = new database.LeadConvert();
      lc.setLeadId(myLead.Id);
      lc.convertedStatus = 'Qualified';
      //Database.ConvertLead(lc,true);
      lc.setDoNotCreateOpportunity(true);
      leadConverts.add(lc);
    }

    if(!leadConverts.isEmpty()){
      for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
        list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
        Integer startIndex = i*100;
        Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
        for(Integer j=startIndex;j<endIndex;j++){
          tempList.add(leadConverts[j]);
        }
        Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
        for(Database.LeadConvertResult lcr : lcrList)
          System.assert(lcr.isSuccess());
      }
    }
}