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
Alex Leem-BruggenAlex Leem-Bruggen 

How to create a Custom Button to Convert 'Prospects' to Leads?

Hi Everyone!

I have recently made a custom object called 'Prospects'. In my company prospects are seen as unqualified leads. Would anyone be able to help me create a convert button on my Prospect custom object which would convert the prospect into a Lead. The 'Lead' object I am referring to is the standard Salesforce Lead object. I have very little knowledge of Apex and Visual Force so any pointers would be much appreciated.

Thanks
Gouranga SadhukhanGouranga Sadhukhan
Apex Code:
global class CallWebService  {

 webservice static string ConvertProspects(string Id)
{
    Prospects p =[Select Id,Field1,.... from Prospects Where Id=:Id];
    Lead l=new Lead();
   l.FirstName=p.FirstName__c;
   .....
  insert l;
  delete p;
  return 'Prospects convert seccessfully';
}

}
Button Code:

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/16.0/apex.js")}
msg= sforce.apex.execute("CallWebService  ","ConvertProspects", {Id: {Prospect__c.Id});

 
Aditya MohanAditya Mohan
Hi write a Javascript Button code like to call Apex Class:
{!REQUIRESCRIPT("/soap/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/32.0/apex.js")}
var result = sforce.apex.execute(
			"ProspectConverion",
			"convertProspectToLead",
			{	
				prospectID : "{!Prospect__c.ID}"
			}
		);

Then write the Apex class:
 
global with sharing class ProspectConverion {
	webService
	static void convertProspectToLead (ID prospectID) {
		List <Prospect__c> lstProspect = new List <Prospect__c>();
		
		//Select the names you want to push to Lead Object
		lstProspect = [
						SELECT
						ID,
						First_Name__c,
						Last_Name__c,
						Email__c,
						Mobile__c
						......
						.....

						FROM Prospect__c
						WHERE ID =: prospectID
						];

		List <Lead> lstLead = new <Lead> ();

		for(Prospect__c prop : lstProspect) {
			lstLead.add(new Lead (
				FirstName = First_Name__c,
				LastName = Last_Name__c,
				Email = Email__c
				.......
				......
				))


		}

		INSERT lstLead;
	}
}

You can refer my blog which discusses about it : ​http://www.saaspie.com/2014/11/03/copying-data-from-one-object-with-a-button-click-in-salesforce/ (http://www.saaspie.com/2014/11/03/copying-data-from-one-object-with-a-button-click-in-salesforce/)
 
Alex Leem-BruggenAlex Leem-Bruggen
Thank you for the help guys!