I have the following visualforce page:
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Convert Leads to Contacts" />
<apex:commandButton value="Convert Leads to Contacts" action="{!convertLead}" onclick="if(!confirm('Do you really want to convert all Lead coincidences to contacts?\nRemember that this process will not create a new opporunity and/or new account. If you are completely sure about following this process, please press on OK button to execute the converting process. ')){return false};"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
Controller method
public List<Lead> leadsToConvert;
public void convertLead(){
// https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_lead.htm
//List<Lead> leadsToConvert;
try
{
leadsToConvert = [Select id, FirstName, Lastname, Company FROM Lead];
Set<String> accNames = new Set<String>();
for(Lead l : leadsToConvert){
accNames.add(l.Company);
}
//Create your map using Name as the key
Map<String,Account> accMap = new Map<String,Account>();
for(Account a : [Select Id, Name From Account Where Name = :accNames]){
accMap.put(a.Name,a);
}
//Assemble List<Database.LeadConvert>
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
for(Lead l : leadsToConvert)
{
//if(leadsToConvert.size() > 0)
//{
Database.LeadConvert lcc = new Database.LeadConvert();
lcc.setLeadId(l.Id);
//if there is an existing account with the same name
//convert the lead into that account by grabbing the
//id from the map above
if(accMap.containsKey(l.Company))
{
lcc.setDoNotCreateOpportunity(True);
lcc.setAccountId(accMap.get(l.Company).Id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true];
lcc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lcc);
}
//set other values
leadConverts.add(lcc);
//}
//else
//{
//showMessage = true;
//message = 'There are no more leads to convert.';
//}
}//End for
showMessage = true;
message = 'Your converting leads to contacts process has been finished successfully, please press OK button to follow with your processes. Thank you for using Lanshore Cleansing App.';
}
catch(Exception e)
{
showMessage = true;
message = 'The following error has ocurred: ' + e.getMessage();
}
}
At pressing on button, it does nothing. Can someone tell me what I am doing wrong?