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
sbbsbb 

Hide Task section on leadconvert.jsp

Is it possible to hide the 'Task' section altogether on LeadConvert.jsp page? I guess building a VisualForce page is the answer, but I would really appreciate if somebody could point me to sample code that does something similar. I want to retain most of the functionality on that page and just customize the layout a bit.

 

Thanks much! 

Best Answer chosen by Admin (Salesforce Developers) 
Andy BoettcherAndy Boettcher

I just did this - it's not too bad.

 

The stock lead convert page is one of those little "hidden gems" that you can't control anything inside of.  You have to roll your own VF page - remove the stock "Convert" button and replace it with a Custom Button that calls this VF page:

 

<apex:page standardController="Lead" extensions="YourAPEXController" title="Convert Lead" id="pgConvertLead">

<apex:form id="frmConvert">

	<apex:actionFunction name="afOpportunity" action="{!doNothing}" rerender="pbsConvert" immediate="true" />

	<apex:pageBlock title="Convert Lead" mode="edit">
	
		<apex:pageBlockButtons >
			<apex:commandButton id="cmdConvert" action="{!convertLead}" value="Convert" />
			<apex:commandButton id="cmdCancel" action="{!cancel}" value="Cancel" />
		</apex:pageBlockButtons>
		
		<apex:messages ></apex:messages>
		
		<apex:pageBlockSection id="pbsConvert" title="Convert Lead" columns="1">
						
			<apex:inputField id="ifOwnerId" value="{!ldSource.OwnerId}" />
			<apex:selectList id="soAccount" value="{!strAccountId}" label="Account Name" size="1">
				<apex:selectOptions value="{!lstCompanyInfo}" />
			</apex:selectList>
			<apex:inputCheckBox id="icCreateOpp" value="{!bolCreateOpp}" label="Do Not Create Opportunity" onclick="afOpportunity()" />
			
		</apex:pageBlockSection>
	
	</apex:pageBlock>

</apex:form>

</apex:page>

 and the controller...

 

	public Lead ldSource {get;set;}
	public Boolean bolCreateOpp {get;set;}
	public String strAccountId {get;set;}
	public String strStatus {get;set;}
	
	//////////////////////////
	// Constructors / GETers
	//////////////////////////
	public YourAPEXController(ApexPages.StandardController scMain) {
		
		ldSource = [SELECT Id, FirstName, LastName, OwnerId, Company, Street, City, State, PostalCOde, Country, Phone, Fax FROM Lead WHERE Id = :scMain.getId()];
		
		bolCreateOpp = false;
		
	}
	
	public List<SelectOption> getlstCompanyInfo() {
		
		String strCompanyWildcard = '%' + ldSource.Company + '%';
		List<Account> lstAcct = [SELECT Id, Name, Owner.Name FROM Account WHERE Name LIKE :strCompanyWildcard];
		
		List<SelectOption> lstCompanies = new List<SelectOption>();
		
		// Add New Account if not found
		lstCompanies.add(new SelectOption('1','Create New Account: ' + ldSource.Company));

		// Add found Accounts to SelectList
		for(Account a : lstAcct) {
			lstCompanies.add(new SelectOption(a.Id, 'Attach to Existing: ' + a.Name + ' (' + a.Owner.Name + ')'));
		}

		return lstCompanies;		
	}
	
	//////////////////////////
	// Action Methods
	//////////////////////////

	public void doNothing() {  }

	public PageReference convertLead() {
		
		// Create LeadConvert object
		Database.LeadConvert lc = new Database.LeadConvert();
		
		lc.setLeadId(ldSource.Id);
		lc.setOwnerId(ldSource.OwnerId);
		if(strAccountId.length() > 1) { lc.setAccountId(strAccountId); }
		lc.setDoNotCreateOpportunity(bolCreateOpp);
		
		// Set Opportunity Name
		if(bolCreateOpp == false) { lc.setOpportunityName(ldSource.Company); }
		
		// Set Lead Converted Status
		LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
		lc.setConvertedStatus(convertStatus.MasterLabel);
		
		// Convert!
		Database.LeadConvertResult lcr = Database.convertLead(lc);
		
		// Mop up Opportunity
		if(bolCreateOpp == false) {
			Opportunity o = new Opportunity(Id=lcr.getOpportunityId());
			update o;
		}
		
		// Redirect...
		PageReference prResult;
		if(lcr.isSuccess()) {
			prResult = new PageReference('/' + lcr.getAccountId());
			prResult.setRedirect(true);
			return prResult;	
		} else {
			return null;
		}
		
	}

 

Hopefully that helps!

 

-Andy

All Answers

Andy BoettcherAndy Boettcher

I just did this - it's not too bad.

 

The stock lead convert page is one of those little "hidden gems" that you can't control anything inside of.  You have to roll your own VF page - remove the stock "Convert" button and replace it with a Custom Button that calls this VF page:

 

<apex:page standardController="Lead" extensions="YourAPEXController" title="Convert Lead" id="pgConvertLead">

<apex:form id="frmConvert">

	<apex:actionFunction name="afOpportunity" action="{!doNothing}" rerender="pbsConvert" immediate="true" />

	<apex:pageBlock title="Convert Lead" mode="edit">
	
		<apex:pageBlockButtons >
			<apex:commandButton id="cmdConvert" action="{!convertLead}" value="Convert" />
			<apex:commandButton id="cmdCancel" action="{!cancel}" value="Cancel" />
		</apex:pageBlockButtons>
		
		<apex:messages ></apex:messages>
		
		<apex:pageBlockSection id="pbsConvert" title="Convert Lead" columns="1">
						
			<apex:inputField id="ifOwnerId" value="{!ldSource.OwnerId}" />
			<apex:selectList id="soAccount" value="{!strAccountId}" label="Account Name" size="1">
				<apex:selectOptions value="{!lstCompanyInfo}" />
			</apex:selectList>
			<apex:inputCheckBox id="icCreateOpp" value="{!bolCreateOpp}" label="Do Not Create Opportunity" onclick="afOpportunity()" />
			
		</apex:pageBlockSection>
	
	</apex:pageBlock>

</apex:form>

</apex:page>

 and the controller...

 

	public Lead ldSource {get;set;}
	public Boolean bolCreateOpp {get;set;}
	public String strAccountId {get;set;}
	public String strStatus {get;set;}
	
	//////////////////////////
	// Constructors / GETers
	//////////////////////////
	public YourAPEXController(ApexPages.StandardController scMain) {
		
		ldSource = [SELECT Id, FirstName, LastName, OwnerId, Company, Street, City, State, PostalCOde, Country, Phone, Fax FROM Lead WHERE Id = :scMain.getId()];
		
		bolCreateOpp = false;
		
	}
	
	public List<SelectOption> getlstCompanyInfo() {
		
		String strCompanyWildcard = '%' + ldSource.Company + '%';
		List<Account> lstAcct = [SELECT Id, Name, Owner.Name FROM Account WHERE Name LIKE :strCompanyWildcard];
		
		List<SelectOption> lstCompanies = new List<SelectOption>();
		
		// Add New Account if not found
		lstCompanies.add(new SelectOption('1','Create New Account: ' + ldSource.Company));

		// Add found Accounts to SelectList
		for(Account a : lstAcct) {
			lstCompanies.add(new SelectOption(a.Id, 'Attach to Existing: ' + a.Name + ' (' + a.Owner.Name + ')'));
		}

		return lstCompanies;		
	}
	
	//////////////////////////
	// Action Methods
	//////////////////////////

	public void doNothing() {  }

	public PageReference convertLead() {
		
		// Create LeadConvert object
		Database.LeadConvert lc = new Database.LeadConvert();
		
		lc.setLeadId(ldSource.Id);
		lc.setOwnerId(ldSource.OwnerId);
		if(strAccountId.length() > 1) { lc.setAccountId(strAccountId); }
		lc.setDoNotCreateOpportunity(bolCreateOpp);
		
		// Set Opportunity Name
		if(bolCreateOpp == false) { lc.setOpportunityName(ldSource.Company); }
		
		// Set Lead Converted Status
		LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
		lc.setConvertedStatus(convertStatus.MasterLabel);
		
		// Convert!
		Database.LeadConvertResult lcr = Database.convertLead(lc);
		
		// Mop up Opportunity
		if(bolCreateOpp == false) {
			Opportunity o = new Opportunity(Id=lcr.getOpportunityId());
			update o;
		}
		
		// Redirect...
		PageReference prResult;
		if(lcr.isSuccess()) {
			prResult = new PageReference('/' + lcr.getAccountId());
			prResult.setRedirect(true);
			return prResult;	
		} else {
			return null;
		}
		
	}

 

Hopefully that helps!

 

-Andy

This was selected as the best answer
sbbsbb

Awesome! Thank you, Andy! I will need to play with this now and expand on it for my needs. Really appreciate your help!

iluuukiluuuk

So big THANK YOU!

:smileyvery-happy:

CharlesDouCharlesDou

That is  awesome!! THANKS A LOT!!!





PrasadVRPrasadVR

Hello Sbb,

 

    If you Know much more about this (or) you have any new ideas about this share with us ,I tried to create new lead conversion process it working good anyhow at some point it shows error as in the below line,here master label means lead status it automatically fetches the lead status but in my case we have lot lead process when i run this it fetches the value  but we are not using this value in lead status in some record types there it shows an error, If you have any idea about this kindely share with us it helps a lot.

 

 LeadStatus convertStatus = [Select Id,MasterLabel from LeadStatus where Isconverted=true limit 1];
          lc.setConvertedStatus(convertStatus.MasterLabel);
Pallavic14Pallavic14
Hi,

Can one of you help me with test class for this custom code.
I have been trying to increase test coverage but lost.

here is my test code.
@IsTest
private class TestXXCSRLeadConvertClass{

        static testMethod void TestXXCSRLeadConvertClass() {
      
       test.startTest();
           Boolean bolCreateOpp;
           String strAccountId;
     String strContactId;
            Lead l = new Lead();
            l.FirstName = 'CRM Testing First';
            l.LastName = 'CRM Testing Last';
            l.Company = 'CRM Testing INCtest';
            l.description = 'Test descr';
            l.city = 'test';
            l.street = 'test';
            l.state = 'CA';
            l.country = 'United States';
            l.status = 'Qualified';
            l.email = 'test@testnetgear.com';
            l.website = 'www.testcrm.com';
            l.ApprovalStatus__c='Approved';
           // l.RecordTypeId='012110000004b9Q';
             
        
            insert l;
       
      Id leadId = l.Id;
  bolCreateOpp = false;
  //Create a reference to the VF page
  PageReference pageRef = Page.XXCSR_LEAD_CONVERT;
        Test.setCurrentPageReference(pageRef);

     //Create an instance of the controller extension and call the autoRun method.
  //autoRun must be called explicitly even though it is "autoRun".
  ApexPages.StandardController sc = new ApexPages.standardController(l);
  XXCSRLeadConvertClass leadconvt = new XXCSRLeadConvertClass(sc);
  leadconvt.autoRun();
   //String nextPage = sc.save().getUrl();
 
      
       List<SelectOption> testacct = new List<SelectOption>();
       testacct = leadconvt.getlstCompanyInfo();
        system.debug(testacct);
    
       
  List<SelectOption> testcon = new List<SelectOption>();
       testcon = leadconvt.getlstContactInfo();
        system.debug(testcon);
 
   leadconvt.doNothing();
 
 
             //Retrieve the converted Lead info and the opps and roles.
   l = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId ,Status, ApprovalStatus__c,
    Company,OwnerId,firstname,lastname,city,country from Lead where Id = :leadId];
         
          system.assert(!l.IsConverted,'Lead Converted' ); 
          test.stopTest();
        

        }
  
        

}

Thanks
Pallavi