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
Sayyad Amjad 7Sayyad Amjad 7 

Lead convert Visual force Page Enable Or Disable Opportunity Creation

Hi All i need a help on to create VF page
i am having Custom Lead__c object i need to create Visual force page 
like thisUser-added imageSame working visule force page i need if any one have Vfpage and class please paste need urgent.
thanks in advance
AnudeepAnudeep (Salesforce Developers) 
As far as I understand what you are looking for is a custom Visualforce Page to override the standard lead convert page

I suggest looking at the sample code here

Let me know if it helps
Sayyad Amjad 7Sayyad Amjad 7
<apex:page controller="LeadConverterClass" sidebar="false" showHeader="false">
    
    <apex:pagemessages />  
    <apex:slds />
    <apex:form >      
        <br/>
        <div class="slds-box" style="width: 98%;margin:auto">                      
            <div class="slds-scope" style="display:{!IF(leadstage == 'Qualified', 'block', 'none')}">
                <h3 class="slds-text-heading_large slds-truncate slds-text-align_center" title="summary title">Lead Conversion Detail</h3>
                
                <div class="slds-form-element ">
                    
                    <div class="slds-grid slds-grid_pull-padded-medium">
                        <div class="slds-col slds-p-horizontal_medium" style="width:50%">
                            <label class="slds-form-element__label" for="account-name">Account Name</label>
                            <div class="slds-form-element__control">
                                <apex:inputField styleClass="slds-input slds-form-element__control" value="{!acc.name}" required="false"/>                                                </div>
                        </div> 
                        
                        <div class="slds-col slds-p-horizontal_medium " style="width:50%">
                            <label class="slds-form-element__label" for="account-number">Contact Name </label>
                            <div class="slds-form-element__control">
                                <apex:inputText styleClass="slds-input slds-form-element__control" value="{!ld.Full_Name__c}" />                                                
                            </div>  
                        </div> 
                        
                    </div><!--1--->
                    
                    <div class="slds-grid slds-grid_pull-padded-medium">
                        <div class="slds-col slds-p-horizontal_medium" style="width:50%">
                            <label class="slds-form-element__label" for="account-name">Opportunity Name</label>
                            <div class="slds-form-element__control">
                                <apex:inputField styleClass="slds-input slds-form-element__control" value="{!opty.Name}" required="false"/>                               
                            </div>
                        </div> 
                        
                        <div class="slds-col slds-p-horizontal_medium" style="width:50%">
                        <label class="slds-form-element__label" for="account-name"></label> <br/> <br/> 
                        <div class="slds-form-element__control">
                         <apex:outputPanel  styleclass="slds-form-element__label"  >
                        <apex:inputCheckbox value="{!NoOpportunity }" /> <br/> 
                       <label class="slds-form-element__label" for="account-name">Note: Do not create a new opportunity upon conversion.</label> 
                        </apex:outputPanel>                            
                        </div>
                    </div>                        
                    </div> <!--2--->      
                </div> 
                <br/>
                
                <div class="slds-scope" align="center" style="margin-top:10px">
                    <apex:commandButton styleclass="slds-button slds-button_brand " action="{!save}" value="Convert"/>        
                    <apex:commandButton styleclass="slds-button slds-button_destructive " action="{!cancel}" value="Cancel"/>        
                </div>
                
            </div>
            
            <div class="slds-scope"  align="center" style="display:{!IF(leadstage == 'Qualified', 'none', 'block')}">
                <apex:commandButton styleclass="slds-button slds-button_destructive " action="{!cancel}" value="Cancel"/>
            </div>
        </div>
    </apex:form>
</apex:page>


-----------------------------------------------------  Class --------------------------------------------------------------------------------------------------------------------
public class LeadConverterClass {
    
    public Id lid {get; set;}
    public RecordType rct {get; set;}
    public List<RecordType > rtlist{get; set;}
    public Lead__c ld {get;set;}
    public Account acc {get;set;}
    public Opportunity__c opty {get;set;}
    public boolean NoOpportunity {get;set;}
    public String selectRecordTypeId {get; set;}
    public String leadstage {get; set;}
    
    public List<Task> tasklist{get;set;}
    public List<Event> eventlist{get;set;}
    
    public LeadConverterClass(){
        
        lid=ApexPages.currentPage().getParameters().get('id');
        
        ld=[ SELECT City__c,Company_Name__c,Converted__c,Country__c,CreatedById,CreatedDate,Email_ID__c,
            Full_Name__c,Id,Industry__c,IsDeleted,Job_Title_Designation__c,LastActivityDate,LastModifiedById,
            LastModifiedDate,LastReferencedDate,LastViewedDate,Last_Name__c,Lead_Source__c,Lead_Stage__c,Lead__c,
            Loss_Reason__c,Middle_Name__c,Mobile_Number__c,Name,OwnerId,Phone__c,Postal_Code__c,Rating__c,Salutation__c,
            State__c,Street__c,SystemModstamp,Website__c FROM Lead__c where id=:lid];
        
        leadstage=ld.Lead_Stage__c;
        
        system.debug('ld>>>>>>>>>>'+ld);
        
        tasklist=[SELECT ActivityDate,Description,Id,IsHighPriority,Priority,Status,Subject,WhatId,WhoId,OwnerId,ReminderDateTime,
                  IsReminderSet  FROM Task where WhatId=:ld.Id ];
        
        system.debug('tasks>>>>>>'+tasklist);
        
        eventlist=[SELECT ActivityDate,CreatedById,CreatedDate,Description,EndDate,EndDateTime,EventSubtype,Id,IsAllDayEvent,IsReminderSet,
                   Location,OwnerId,ReminderDateTime,StartDateTime,Subject,Type,WhatId,WhoId FROM Event where WhatId=:ld.Id ];
        
        system.debug('events>>>>>>'+eventlist);
        
        rct=[select id, Name, SobjectType from RecordType where SobjectType='Lead__c' 
             AND IsActive = true and Name='Read Only Layout' ];  
        
        if(leadstage == 'Qualified'  ){
            
            acc = new Account();
            acc.name=ld.Company_Name__c;
            
            opty = new Opportunity__c();
            opty.Name = ld.Company_Name__c;
        }
        else{
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,
                                                          'Please Ensure Lead Is Qualified Before Convert');
            ApexPages.addMessage(msg);
        }
    }
    
    public List<SelectOption> getRecordList(){
        List < SelectOption > options = new List < SelectOption > ();
        rtlist=[select id,Name from RecordType where IsActive = true and SobjectType='Opportunity__c' and Name!='Sampling Read Only'];
        options.add(new SelectOption('None', 'None'));
        for(RecordType rt:rtlist){
            options.add(new SelectOption(rt.Id, rt.Name));
        }
        return options;
    }   
    
    public PageReference save(){
        PageReference pageRef = new PageReference('/');
      if(ld.Converted__c!=true){
            
            //acc.Customer_Segment__c=ld.Customer_Segment__c;
            //acc.Industries_Served__c=ld.End_Application__c;
            acc.Phone=ld.Phone__c;
            acc.Industry=ld.Industry__c;
            acc.Website=ld.Website__c;
            acc.BillingStreet =ld.Street__c;
            acc.BillingCity    =ld.City__c;
            acc.BillingState =ld.State__c;        
            acc.BillingCountry =ld.Country__c;            
            acc.BillingPostalCode=ld.Postal_Code__c;
            //acc.CurrencyIsoCode=ld.CurrencyIsoCode;

            insert acc;
            
            // Insert a Contact
            Contact con = new Contact();
            con.AccountId=acc.id;
            con.Email=ld.Email_ID__c;
            con.Salutation=ld.Salutation__c;
            con.FirstName=ld.Name;
            con.LastName=ld.Last_Name__c;
            con.Phone=ld.Phone__c;
            con.MobilePhone=ld.Mobile_Number__c;
            con.LeadSource =ld.Lead_Source__c;
            //con.Decision_Maker__c=ld.Decision_Maker__c;
            con.Title=ld.Job_Title_Designation__c    ;
           // con.CurrencyIsoCode=ld.CurrencyIsoCode;
            
            insert con;
            
            // Insert an Opportunity
            if(NoOpportunity!=true){

            opty.Account_Name__c=acc.id;
            opty.Stage__c='None';
            opty.Lead_Source__c=ld.Lead_Source__c;
            //opty.RecordTypeId=selectRecordTypeId;
            //opty.CurrencyIsoCode=ld.CurrencyIsoCode;
            insert opty;
            }
            List < Task > task = new List < Task > ();
            for (Task ts: tasklist) {
                
                Task ta=new Task();
                ta.WhatId=acc.Id;
                ta.Status=ts.Status;
                ta.Subject=ts.Subject;
                ta.ActivityDate=ts.ActivityDate;
                ta.Description=ts.Description;
                ta.WhoId=ts.WhoId;
                ta.Priority=ts.Priority;
                ta.OwnerId=ts.OwnerId;
                ta.ReminderDateTime=ts.ReminderDateTime;
                ta.IsReminderSet=ts.IsReminderSet;
                
                task.add(ta);
            }
            insert task;
            
            
            List < Event > event = new List < Event > ();
            for (Event ev: eventlist) {
                
                Event evt=new Event();
                evt.WhatId=acc.Id;
                evt.Subject=ev.Subject;
                evt.ActivityDate=ev.ActivityDate;
                evt.Description=ev.Description;
                evt.WhoId=ev.WhoId;
                evt.OwnerId=ev.OwnerId;
                evt.ReminderDateTime=ev.ReminderDateTime;
                evt.IsReminderSet=ev.IsReminderSet;
                evt.EndDateTime=ev.EndDateTime;
                evt.EventSubtype=ev.EventSubtype;
                evt.IsAllDayEvent=ev.IsAllDayEvent;
                evt.Location=ev.Location;
                evt.StartDateTime=ev.StartDateTime;
                evt.Type=ev.Type;
                
                event.add(evt);
            }
            insert event;
            
            ld.Converted__c=true;
            ld.RecordTypeId=rct.Id;
            update ld;
            
            
            
            pageRef = new PageReference('/'+acc.id);
            pageRef.setRedirect(true);
            
        }
        else
        {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,
                                                          'This Lead was Already Converted!!!');
            ApexPages.addMessage(msg);
            
            pageRef = new PageReference('/apex/LeadConvertPage?='+lid);
            pageRef.setRedirect(false);
            
        }
        
        return pageRef; 
    }
    
    public PageReference cancel(){
        
        PageReference pageRef = new PageReference('/'+lid);
        pageRef.setRedirect(true);
        return pageRef;    
        
    }
}


It is now working now i need to add for the user they can chose exsting account too add i am stuck over there can any one please help me out

like this User-added image
Sayyad Amjad 7Sayyad Amjad 7
@Anudeep  Please help
jins asjwjins asjw
Is this good idea to use this script for coaching or educational type website? I'm asking for coahcing training program (https://thecoachtrainingacademy.com/coach-training-programs/2-day-fast-track/) page of my dynamic website.
Audrey WayneAudrey Wayne
Is this smart thought to utilize this content for training or instructive sort site? I'm requesting the saving bees (https://beenecklace.net/category/save-the-bees-necklace/) program. 
Kelvin WilbertKelvin Wilbert
It seems great can I use this script for the machines rating program site? Could you tell me that it is okay to use this for the self-propelled lawnmower (https://www.machinesrating.com/best-self-propelled-lawn-mower-under-300/) program? If yes then thanks in advance.
boris bensonboris benson
I will use this smart idea for website (https://vikingclothing.net/).
mark huntingmark hunting
Can I use this script for the electric (https://www.beingsmoked.com/electric-smoker-vs-propane-smoker/) smoker site?
Sherman AllisterSherman Allister
I want to use this script for mud mixing (https://mudreview.com/how-to-mix-your-mud-secret-recipes/) page of mud review site.
joseph harllyjoseph harlly
I am going to suggest you looking at the sample code here (https://www.macmillermerch.store/phone-cases/).
Michael Phillip 2Michael Phillip 2
This seems quite good an amazing script. I want to use this (https://nfmerch.net/category/hats/) on my nf program Can I use this.?
Martin KevinMartin Kevin
This is a very smart idea. Thank you for sharing with us. I want to use this script for wixdek (https://wixdek.com/). Is it possible that I can use this? Much obliged.
Dominic FinchDominic Finch

I must say this is a really impressive idea. is it safe to use this script for the AMD Creative Website Design (https://www.amdbirmingham.com/) page? Thanks in advance.
Stuart PhillipStuart Phillip
It appears to be incredible would I be able to utilize this content for the mattress guides program site? Could you let me know that it is OK to utilize this for the (https://mattressguides.in/best-mattresses/best-mattress-in-india/) program? Assuming yes then, at that point, thanks ahead of time.
Harry Joe 1Harry Joe 1
It seems amazing. Could I use this content for the mayer cleaning website? May I use this for the End of Tenancy Cleaning Service Egham (https://www.mayercleaning.co.uk/services/moving-cleaning/egham.php) program? If yes, thanks ahead of time.
 
Gabariel KevinGabariel Kevin
Would I be able to use this content on the aspire restoration website? Would it be OK if I utilized this for the (https://aspirerestorationltd.co.uk/brick-cleaning-london/) program? If yes, then thanks ahead of time.
 
Matthew Wilson 16Matthew Wilson 16
My first impression is that this is an excellent idea. Is it safe to use this script on the car key replacement (https://lostcarkeys247.co.uk/car-keys-replacement/)'s website? I appreciate your help.