You need to sign in to do that
Don't have an account?

after convert ,i need to delete my leads records automatically
{!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);
}
}
{!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);
}
}
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")}
var accnt = new sforce.SObject("Account");
//caprturing Mylead id for deletion after insertion of account
var accs='{!My_Leads__c.Id}';
//Querying record types of account
var recType=sforce.connection.query("SELECT name, id FROM RecordType" );
var records = recType.getArray("records");
// checking for business account type
accnt.Name='{!My_Leads__c.Company__c}';
if(accnt.Name !="")
{
accnt.RecordTypeId = records[0].Id;
//creating account
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');
}
//creating contact
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');
//Deleting the Mylead record
var leadlist=sforce.connection.query("Select id, Company__c, Lead_Name__c from My_Leads__c where id='"+accs+"'");
var records = leadlist.getArray("records");
alert(records[0].Id);
var data = Array();
for(var i=0;i< records.length; i++)
data.push (records[i].Id);
alert (data);
var deleteIds= sforce.connection.deleteIds(data);
alert (deleteIds);
window.location.reload();
}
else{
alert('Error : '+result);
}
}
//Creating person account
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');
var leadlist=sforce.connection.query("Select id, Company__c, Lead_Name__c from My_Leads__c where id='"+accs+"'");
alert (leadlist);
var records = leadlist.getArray("records");
alert(records[0].Id);
var data = Array();
for(var i=0;i< records.length; i++)
data.push (records[i].Id);
alert (data);
var deleteIds= sforce.connection.deleteIds(data);
alert (deleteIds);
window.location.reload();
}
else
{
alert('Error : '+result);
}
}
This my final answer
All Answers
From your statement I understand that you want to delete the lead record once it is converted.
Proposed Solution:
Step 1: Create two Unique Fields one on Lead and one on Account.
e.g. LeadUniqueSLNo__c the field on Lead can be of type Auto Number (External ID)
and the one on Account LeadUniqueSLNoAcct__c can be text/integer
Step 2: Use custom Lead mapping to map LeadUniqueSLNo__c to LeadUniqueSLNoAcct__c
Step 3: Create a Trigger on Account that should execute upon creation of records.
When an account record is created then check in the trigger if the LeadUniqueSLNoAcct__c is not null
if its not Null then fire SOQL to get the Lead record by querying for LeadUniqueSLNo__c
Then delete the Lead record you get from the SOQL result
Let me know if you need any furter clarification.
Thanks,
Rosh
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")}
var accnt = new sforce.SObject("Account");
//caprturing Mylead id for deletion after insertion of account
var accs='{!My_Leads__c.Id}';
//Querying record types of account
var recType=sforce.connection.query("SELECT name, id FROM RecordType" );
var records = recType.getArray("records");
// checking for business account type
accnt.Name='{!My_Leads__c.Company__c}';
if(accnt.Name !="")
{
accnt.RecordTypeId = records[0].Id;
//creating account
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');
}
//creating contact
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');
//Deleting the Mylead record
var leadlist=sforce.connection.query("Select id, Company__c, Lead_Name__c from My_Leads__c where id='"+accs+"'");
var records = leadlist.getArray("records");
alert(records[0].Id);
var data = Array();
for(var i=0;i< records.length; i++)
data.push (records[i].Id);
alert (data);
var deleteIds= sforce.connection.deleteIds(data);
alert (deleteIds);
window.location.reload();
}
else{
alert('Error : '+result);
}
}
//Creating person account
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');
var leadlist=sforce.connection.query("Select id, Company__c, Lead_Name__c from My_Leads__c where id='"+accs+"'");
alert (leadlist);
var records = leadlist.getArray("records");
alert(records[0].Id);
var data = Array();
for(var i=0;i< records.length; i++)
data.push (records[i].Id);
alert (data);
var deleteIds= sforce.connection.deleteIds(data);
alert (deleteIds);
window.location.reload();
}
else
{
alert('Error : '+result);
}
}
This my final answer