You need to sign in to do that
Don't have an account?
ravikanth321
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}';
});
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}';
});
I made some edits in your script. Please refer the same:
If you are facing issues with jquery, then you can use simple javascript instead like:
https://success.salesforce.com/answers?id=90630000000gzvlAAA
Can you share your controller's code with me not Javascript?
{
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;
}
}