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
BenzingaBenzinga 

Trying to create a custom convert button for leads

Hi, I'm trying to create a custom button to convert leads into accounts, but NOT contacts.

 

Is there anyway to do this? I don't know how to create Salesforce buttons at all.

BenzingaBenzinga

Are there any tutorials for button creation?

Ritesh AswaneyRitesh Aswaney

Salesforce allows you to prevent an Opportunity on Lead Conversion, not sure if you can suppress Contact creation.

 

Here are some resources to get you started :

 

http://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/

 

http://cloudyk.com/salesforce/salesforce-lead-conversion-do-not-create-opportunity-by-default/

 

I reckon you might have to explicitly delete the Contact created by using the ConvertedContactId, which is set on a Lead after conversion.

jkucerajkucera

Ritesh - a simpler way is to use a Contact trigger to delete any new contacts created (but not existing contacts merged into).  

 

Custom lead convert is really hard to code correctly as there is a lot going on - activities are moved, campaign members moved, triggers & workflow firing, etc.  

 

You can probably get away with a before insert contact trigger that queries to see if any the new contacts match any in lead.convertedContactID.  If so, you can delete those contacts or fail the insert with .addError() 

BenzingaBenzinga

Without a custom lead converter though, I imagine I'd have the problem of contact info, that currently goes into contacts, and contacts alone, not being switched over. Theoretically there'd be a way to, along with deleting the created contact, copy the contact information over to the account created as well? I'm not sure how I'd go about that. I'm just guessing that this functionality is possible, as well.

 

I'm not adverse to learning how to code something in Salesforce - I do some light programming (in Python), so whatever Salesforce uses shouldn't be too hard.

 

 

jkucerajkucera

Customer lead convert wouldn't make it easier to get the lead fields mapped to Account instead of contact - you'd have to use essentially the same code whether in a trigger, or part of your custom lead convert process.

 

Its up to you, but if you go the trigger route, you can grab the lead fields & add them to the contact's parent and delete the contact.  

nGenx PMnGenx PM

Is there a way to simply insert a dependency INTO the convert process?

 

I simply want to make sure that before my Sales Team converts a LEAD to an ACCOUNT that (checkbox A=True) or the Lead wont convert.

 

Is there a way to do that without rewriting the entire Java Code?

jkucerajkucera

You can create a validation rule to throw an error upon lead convert if that other field isn't true.  For example, if you don't want to allow converting leads where DoNotCall=TRUE, the Error Condition Formula would be:

 IsConverted  = TRUE  &&  DoNotCall =TRUE

nGenx PMnGenx PM

worked like a charm...

Thanks so much!

Hemalatha  ParuchuriHemalatha Paruchuri
{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")}

var accnt = new sforce.SObject("Account");
var recType=sforce.connection.query("SELECT name, id FROM RecordType" );
//alert(recType);
var records = recType.getArray("records");
//alert(records);
accnt.Name='{!My_Leads__c.Company__c}';
if(accnt.Name !="")
{
accnt.RecordTypeId = records[0].Id;
//alert(records[0].Id);

accnt.Id = '{!Account.Id}';
accnt.Name = prompt('','{!My_Leads__c.Company__c}');
accnt.OwnerId='{!My_Leads__c.OwnerId}';

var result = sforce.connection.create([accnt]); 
if(result[0].getBoolean("success")) 

alert('Account created successfully'); 

}
var cnt= new sforce.SObject("Contact"); 
cnt.Id = '{!Contact.Id}';
cnt.OwnerId='{!My_Leads__c.OwnerId}';
cnt.AccountId=result[0].id;
cnt.lastName = prompt('','{!My_Leads__c.Lead_Name__c}');

var result = sforce.connection.create([cnt]);
 if(result[0].getBoolean("success"))

alert('contact created successfully'); 
window.location.reload();

}

else{
  alert('Error : '+result);
}
}
else
{
accnt.RecordTypeId=records[1].Id;
//alert(records[1].Id);
accnt.Id = '{!Account.Id}';
accnt.LastName = prompt('','{!My_Leads__c.Lead_Name__c}');
accnt.OwnerId='{!My_Leads__c.OwnerId}';

var result = sforce.connection.create([accnt]); 
if(result[0].getBoolean("success")) 

alert('Account created successfully'); 

}
else
{
 alert('Error : '+result);
}


}