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
ravikanth321ravikanth321 

jQuery Is Not Defined .

Hii I have written a Code For Onclick Button Which has to disable after first click and has to call a method which converts lead in to Opportunity,Accounts and Contact..
Code:
{!REQUIRESCRIPT("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js")}
  var $ = jQuery.noConflict();
$(document).off('click', '.btn').on('click', '.btn',function(e) {
    $('input[name*=custom_convert]').attr('class', 'btnDisabled');
      $('input[name*=custom_convert]').attr('value','Converting...');
      
      console.log('*****clicked*********');
window.location='/apex/LeadConvertOverride?id={!Lead.Id}';
    });User-added image
 
Pankaj_GanwaniPankaj_Ganwani
Hi Rashmi,

I made some edits in your script. Please refer the same:
 
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js")} 
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js")} 

var $ = jQuery.noConflict(); 
$(document).off('click', '.btn').on('click', '.btn',function(e) { 
$('input[name*=custom_convert]').attr('class', 'btnDisabled'); 
$('input[name*=custom_convert]').attr('value','Converting...'); 

console.log('*****clicked*********'); 
window.location='/apex/LeadConvertOverride?id={!Lead.Id}';
});

 
ravikanth321ravikanth321
Hi Pankaj Thanks ,I Updated with your Code But Still i am getting the same error.
Pankaj_GanwaniPankaj_Ganwani
Hi,

If you are facing issues with jquery, then you can use simple javascript instead like:
 
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js")} 
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js")} 

console.log('*****clicked*********'); 
this.disabled = true;
this.value='Converting...';
this.className = 'btnDisabled';
window.location='/apex/LeadConvertOverride?id={!Lead.Id}';

 
ravikanth321ravikanth321
Its Working But Not Showing as "Converting....."
ravikanth321ravikanth321
Its Working If I Convert Lead As a System Administartor ,But If I LogIn as a Different Profile (To Whom I assigned That Lead) Its Not Working Pankaj.Could You Please Help me.
Pankaj_GanwaniPankaj_Ganwani
Any javascript errors you are getting in console? You can refer below mentioned link for more information:

https://success.salesforce.com/answers?id=90630000000gzvlAAA
ravikanth321ravikanth321
Hi Pankaj Lead Is Convertable by those profiles  But Its Creating Duplicates.
Pankaj_GanwaniPankaj_Ganwani
You mean to say that it is creating Accounts and Contacts twice?
ravikanth321ravikanth321
Yes Pankaj I used the same code which you suggested for Custom Button,That Is Working Fine If That Lead Is assigned To Me (System Admin) and converting that lead as Syatem admin ,But If I assign the same lead to any other profile and trying to convert that lead by logging as that profile It Creating Duplicates Oppurtunities,Accounts and Contacts.
Pankaj_GanwaniPankaj_Ganwani
Hi,

Can you share your controller's code with me not Javascript?
ravikanth321ravikanth321
public class LeadConvertOverride
{
    Public String leadId;
    Public Boolean bDoNotsendOpp{get;set;}
    public string AccountId;
    Public String strContactId;
    public string OpportunityId;
    public string strAccountPhone;
    public string strAccountName{get;set;}
    public string LeadCompName{get;set;}
    public string strLeadStatus;
    public string strLeadStatusdis;
    public string strOppertunityName{get;set;}
    public string strModifiedPhone;
    Public Task ObjTask {get;set;}
    List<Lead_History__c> leadhistorytoupdate = new List<Lead_History__c>();
    Database.LeadConvertResult lcr;
    Public string contactPhone; // Amit Added : US435709 :- Contact Phone field Phone Number Format not working as expected
    public LeadConvertOverride(){}
    public LeadConvertOverride (ApexPages.StandardController controller) {}
    
    public PageReference convertLeadMethod()
    {
        PageReference pr;
        leadId = ApexPages.CurrentPage().getParameters().get('Id');
        System.debug('leadId#######'+leadId);
        List<Lead> listLead=[select id,OwnerId,name,Status,Company ,Phone,Modified_Phone__c,Email,Lead_Status_Disposition_Code__c,Expected_Closed_Date__c from Lead where id=:leadId and IsConverted = false];
        
        Lead d= new lead();
        
        if(listLead.size()>0){
            d=listLead[0];
        }else
        {
            Lead listLeadConv=[select id,convertedopportunityid from Lead where id=:leadId and IsConverted = true];
            return (new Pagereference('/'+listLeadConv.convertedopportunityid)); 
        }
        
        LeadCompName       = d.Company;
        system.debug('Phone:'+d.Phone);
        if(d.Phone.length()==10)
            contactPhone=formatPhonenumber(d.Phone);
        
        system.debug('--Final---->'+contactPhone);
        if (d.Phone != NULL) {
            d.Phone = d.Phone.replace('-', '');
            d.Phone = d.Phone.replace('(', '');
            d.Phone = d.Phone.replace(')', '');
            d.Phone = d.Phone.replace(' ', '');
            strAccountPhone    = d.Phone;
        }
        
        else 
        {
            strAccountPhone    = d.Phone;
        }    
        strLeadStatus      = d.Status;
        strLeadStatusdis   = d.Lead_Status_Disposition_Code__c;
        strModifiedPhone   = d.Modified_Phone__c;
        
        List<Account> accList = new List<Account>();
        
        // Added for RecordType Check
        Id recordType =null;
        for(RecordType r: [Select id From RecordType r where r.SobjectType = 'Account' and r.DeveloperName = 'Prop_Sales'])
        {
            recordType  = r.id;
        }
        
        accList = [Select Id, Name,Phone FROM Account where RecordTypeId=:recordType and(Name=:LeadCompName or Phone=:strAccountPhone)];
        // RecordType Check End
        // Added String.isBlank(strModifiedPhone)check by deepak/aditya 30 jan 2014 PRJ0005K9Q - OPEN 2014 – Pipeline Enhancements 
        system.debug('@1'+ strLeadStatus      +strLeadStatusdis   + strModifiedPhone   );
        System.Debug('**************** '+d.Expected_Closed_Date__c+' ************ '+ System.Today());
        if((accList.size()==0 && strLeadStatusdis =='Qualified' &&  String.isBlank(strModifiedPhone)) && d.Expected_Closed_Date__c <> NULL && d.Expected_Closed_Date__c > System.Today())
        {
            Database.LeadConvert lc = new Database.LeadConvert();
            lc.setLeadId(leadId);
            
            // lc.setAccountId(accList[0].Id)
            LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
            lc.setConvertedStatus(convertStatus.MasterLabel);
            globalStaticVariables.isLeadConvertInProgress = True;
            try
            {
                lcr = Database.convertLead(lc);
            }
            Catch (Exception e)
            {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error:Lead convert failed.');
                ApexPages.addMessage(myMsg);
            }
            Lead CurrentLead_converted = [select id,convertedAccountId, DoNotcall, Opt_Out_Reason__c, convertedContactId,convertedOpportunityId from Lead where id=: leadId];
            AccountId = CurrentLead_converted.convertedAccountId;
            strContactId = CurrentLead_converted.convertedContactId;
            
            //Added by Rabia for updating Lead History for OPEN-TCA-SF-Allant-Corrections project
            //Date - 16th Sept 2014
            List<Lead_History__c> lh = [select Contact__c from Lead_History__c where Lead__c =: leadId];
            if(lh.size() > 0){
                for(Lead_History__c l: lh){
                    l.Contact__c = strContactId;
                    leadhistorytoupdate.add(l);              
                }
            }
            update leadhistorytoupdate;
            //End of addition by Rabia
            
            //===== Added by Arvind on 10/09/2015 for User Story: US263060 
            
            List<Phone_DNC_Related_Record__c> ldJunctionUpdLst = new List<Phone_DNC_Related_Record__c>();
            
            for(Phone_DNC_Related_Record__c Ldj : [Select id,Phone_DNC_ID__c, Lead_ID__c, Opportunity_Id__c from Phone_DNC_Related_Record__c where Lead_Id__c =:LeadId]){               
                ldJunctionUpdLst.add(new Phone_DNC_Related_Record__c(Id = Ldj.id, Lead_ID__c=null, Phone_DNC_Id__c=Ldj.Phone_DNC_ID__c, Opportunity_ID__c=CurrentLead_converted.ConvertedOpportunityId));
            }    
            if(ldJunctionUpdLst.size()>0)              
                update ldJunctionUpdLst;
            
            //===== User Story: US263060 Addition End
            
            
            
            
            if(strContactId != null)
            {
                contact c = [select System_Generated__c,Disclosure_presented__c from contact where id = :strContactId];
                c.System_Generated__c = true;
                c.Disclosure_presented__c = true;
                c.Disclosure_Old_Email__c = d.Email;
                if(contactPhone<>null && contactPhone<>'')
                    c.Phone=contactPhone;
                update c;
            }
            OpportunityId = CurrentLead_converted.convertedOpportunityId;
            // Added to populate DoNotCall on Opportunity
            if(OpportunityId != null)
            {
                Opportunity Op = [select Do_Not_Call__c, Opt_Out_Reason__c from Opportunity where id = :OpportunityId];
                Op.Do_Not_Call__c = CurrentLead_converted.DoNotCall;
                Op.Opt_Out_Reason__c  = CurrentLead_converted.Opt_Out_Reason__c;
                update Op;
            }
            
            
            pr=new Pagereference('/'+OpportunityId);  
            
            return pr;
            
        }
        else {
            
            pr = new pagereference('/apex/CustomLeadConvert?id='+ApexPages.CurrentPage().getParameters().get('Id'));
            pr.setRedirect(true);
            return pr;
            
        }
        
    }
    
    //Amit: Added to format the contact phone number to salesforce format
    //US435709 :- Contact Phone field Phone Number Format not working as expected
    Public String formatPhonenumber(string phNumber){
        String phone=phNumber;
        string first3numbers='('+phone.left(3)+')';
        string second3numbers=+' '+phone.substring(3,6);
        string third4numbers='-'+phone.substring(6,10);
        string finalPhoneNumber=first3numbers+second3numbers+third4numbers;
        system.debug('-phone-'+phone);
        system.debug('--'+'('+first3numbers+')');
        system.debug('--'+' '+second3numbers);
        system.debug('--'+'-'+third4numbers);
        system.debug('-Final Number-'+finalPhoneNumber);  
        return finalPhoneNumber;
    }
    
}
Pankaj_GanwaniPankaj_Ganwani
Is there any trigger or process builder on lead which is getting fired after lead conversion and causing the creation of Account, Contact and Opportunities separately?
ravikanth321ravikanth321
No Pnakaj I checked all Workflows and Triggers.