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
Prema -Prema - 

How to create a custom button on custom object "lead" on the basis of Status , I need to convert it into Accounts and Contacts.

Best Answer chosen by Prema -
Shweta AlwaniShweta Alwani
Hi prema,

You can take help of below link to create a custom button on custom object : 

http://www.mstsolutions.com/blog/content/creating-custom-button-javascript-salesforce

Create a javascript button and call controller(apex class) using sforce method as describe in above link.Create a method in class that will take lead id as parameter and will convert that lead into accounts and contacts. Call that method from script. Please take help of above link.

Thanks
Shweta
 

All Answers

Shweta AlwaniShweta Alwani
Hi prema,

You can take help of below link to create a custom button on custom object : 

http://www.mstsolutions.com/blog/content/creating-custom-button-javascript-salesforce

Create a javascript button and call controller(apex class) using sforce method as describe in above link.Create a method in class that will take lead id as parameter and will convert that lead into accounts and contacts. Call that method from script. Please take help of above link.

Thanks
Shweta
 
This was selected as the best answer
Prema -Prema -
Hello Shweta, Thanks for your revert. Please help me what I am doing wrong here as when i click on the button depending upon the Status picklist value it's not creating the account and contact record.
global class ConvertLeadCustomClass
{  

    webservice static void method1(ID tid)
    { 

        List<Account> accList=new List<Account>(); 
        List<Contact> conList=new List<Contact>(); 


        Map<id,id> projmap=new Map<id,id>();         

        for(Custom_Lead__c lead:[select Stage__c from Custom_Lead__c where Custom_Lead__c.Id=:tid])
        { 
            if(lead.Stage__c=='Closed Converted')
            {
                Account a= new Account();
                a.Name='ConvertedLeadAccount';
                accList.add(a);
                Contact c=new Contact();
                c.LastName=a.Name;
                c.AccountID=a.Id;
            }
        }
        if((conList.size()>0)&&(accList.size()>0))
        {
        insert accList;
        insert conList;
        }
                 
        
    } 

} 
 

Buttons code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
a = sforce.apex.execute("ConvertLeadCustomClass","method1",{tid:"{!Custom_Lead__c.Id}"}); 

if(a == "It has been converted Successfully"){ 

alert(a); 

} 

else{ 

location.reload(); 

}

 
Prema -Prema -
Sorry the Javascript button will be :
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}  
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}  
a = sforce.apex.execute("ConvertLeadCustomClass","method1",{tid:"{!Custom_Lead__c.Id}"});  

if(a!=null)
{  
a="It has been successfully Converted";
alert(a);  
}  

else{  
location.reload();  

}

It's creating Account but not Contact..I have no idea why
 
Prema -Prema -
This is creating account only when I am commenting the Contact part. otherwise if i uncomment it , it shows this error. Please help me
User-added image
Prema -Prema -
Ok i got it. It was jjst the issues of Validation rule while inserting the contact.
Shweta AlwaniShweta Alwani
Hi prema,

Your problem has been solved ? or still you are getting some problem ?