• Casey Vernia
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hello, I was wondering if someone would be able to assist me with something.

 

We are going to start leveraging leads in our organization.  All of the standard salesforce lead conversion functionality is working great, but the only problem is that we only want to create opportunities, not contacts and accounts when the lead is converted.  I have found some code online and started messing around with it, but it's still creating the account and the contact upon lead conversion.  Is there a way that I can suppress the creation of the contact and the account and just convert the opportunity?  (apex class is first part of code, visualforce is in the bottom)

 

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 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);
        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;
    }
    Public PageReference RedirecttoLead(){
        PageReference Page = new PageReference('https://ap1.salesforce.com/'+leadId);
        Page.setRedirect(true);
        return 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>