Skip to content

Instantly share code, notes, and snippets.

@nithesh1992
Created February 22, 2017 15:04
Show Gist options
  • Save nithesh1992/3ebc8f26718aef67339934bb86c7aede to your computer and use it in GitHub Desktop.
Save nithesh1992/3ebc8f26718aef67339934bb86c7aede to your computer and use it in GitHub Desktop.
public class ConvertExt {
public Lead lead = new Lead();
public Id Lid, accId, conId, oppId;
public Boolean isConverted = false;
public ConvertExt(ApexPages.StandardController stdController){
Lid = (Id)stdController.getRecord().id;
lead = (Lead)stdController.getRecord();
System.debug(Lid);
}
public Lead getLead(){
return lead;
}
public PageReference convertLead(){
lead = [SELECT Id ,LastName,Company,Status, OwnerId FROM Lead WHERE Id =:Lid LIMIT 1];
Database.LeadConvert ldconvert = new Database.LeadConvert();
ldconvert.setLeadId(lead.id);
ldconvert.setOwnerId(lead.OwnerId);
ldconvert.ConvertedStatus = 'Closed - Converted';
ldconvert.setSendNotificationEmail(true);
try{
Database.LeadConvertResult result = Database.convertLead(ldconvert);
System.Debug('Conversion Result: ' + result.isSuccess());
if(result.isSuccess()){
isConverted = true;
}
}
catch(DmlException e){
System.debug(e.getCause());
}
PageReference returnPage = new PageReference('/apex/afterConvert?id='+ Lid);
returnPage.setRedirect(true);
return returnPage;
}
public boolean getIsConverted() {
if(isConverted || lead.Status == 'Closed - Converted')
{
isConverted = true;
}
return isConverted;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment