function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anishaanisha 

Convert Lead to Only Opportunity

Hi

    We want to create a custom button for leadconvert and it will be converted to opportunity only(not account and contact) and it will check wheither the rating is hot or not.......plz help

 

My controller Class :

 

public class leadController
{
    Public lead lObj;
    Public Id leadId;
    public leadController(ApexPages.StandardController stdController)
    {
        leadId = ApexPages.currentPage().getParameters().get('id');
        lObj = (leadid == null) ? new Lead():[SELECT Name, Rating from lead where id =: leadid];
    }
    public PageReference autoRun()
    {
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(leadId);
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        if(lObj.Rating == 'Hot'){
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        Id oppId = lcr.getOpportunityId();
        PageReference Page = new PageReference('https://ap1.salesforce.com/'+oppId);
        Page.setRedirect(true);
        return Page;
        }
        else{
        lObj.addError('Lead cannot be converted without Product Selection !');
        lObj.addError('Please Select Atleast One Product');
        }
        return null;
    }
    Public PageReference RedirecttoLead(){
        PageReference Page = new PageReference('https://ap1.salesforce.com/'+leadId);
        Page.setRedirect(true);
        return Page;
    }
}

My Visualforce Page:

<apex:page standardController="lead" cache="true" action="{!autorun}" extensions="leadController" >
<br/><br/>
<apex:messages style="color:red; font-weight:bold; text-align:center;"/>
<apex:form >
<center>
<apex:commandLink value="Redirect to Lead" style="color:blue; font-weight:bold;" action="{!RedirecttoLead}"/>
</center>
</apex:form>
</apex:page>

Navatar_DbSupNavatar_DbSup

Hi,


You can open this page on the custom button click .for creating a custom button follow the below steps


Step->customize->leads->Buttons and Links-> Click on New


1. Enter the Custom button Label and Name.
2. Select Behaviour=Execute JavaScript
3. Content Source=OnClick JavaScript
4. Enter window.location='/apex/convertlead?id='+'{!Lead.Id}'; in Blank space
5. Click on save button

After creating the custom button add this on your page lead page layout.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.