Created
February 22, 2017 15:04
-
-
Save nithesh1992/3ebc8f26718aef67339934bb86c7aede to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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