+ Start a Discussion
Hemalatha  ParuchuriHemalatha Paruchuri 

Custom object(like lead) convert button like account and contact

Hi,

I have  a custom object like objectA(like lead) i need to conver lead account and contact using button ..how it is possible
Best Answer chosen by Hemalatha Paruchuri
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);
}


}

All Answers

ManojSankaranManojSankaran
Hi Hema,

This can be acheieved using VF Page. Below are the steps that you need to follow.
1. Create a VF Page with Standard Controller as the custom Object.
2. In the VF Page allow user to select which records to create.(As a check box)
3. In convert button write a logic to create the respective object.
             first create account, 
                      then, contact and relate it with account created.

Let me know if you need any help on this. If this really solves your porblem mark it as answer.


Thanks
Manoj S
 
Hemalatha  ParuchuriHemalatha Paruchuri
Thanks for replying ManojSankaran,

i need to develope one button in custom object (like lead object) when click on button create account and contact 
ManojSankaranManojSankaran
Yes Hema,

That is the first step to do the converstion proces. VF Page depends on the complexity that you have. It can also be achieved using Javascript Button.


Thanks
Manoj S
Hemalatha  ParuchuriHemalatha Paruchuri
Can u please send me the code javascript or visualforce page
ManojSankaranManojSankaran
it may take time to write a VF Page and Javascript. Will share after some time. Till then try implement that using VF Page.

Below are the steps

1. StandardController should be your custom object.
2. Add an extenstion.
3. Display 3 Checkboxes in the page with (Create Account, Create Contact and Create Task)
4. Add a button in the page (Let Say Convert)
5. Write a controller method which will get the id of the custom object from the url.
6. Query the required field needed to create a account and contact from the Custom Object
7. Insert the record into salesforce.

Let me know if you know more details to do this.


Thanks
Manoj S
Hemalatha  ParuchuriHemalatha Paruchuri
in custom object  i need to develope one custom button like convert without using vf pages how it is possible
ManojSankaranManojSankaran
Yes. Thats the Idea to start with.



Thanks
Manoj S
Hemalatha  ParuchuriHemalatha Paruchuri
Hi manoj,

I need javascript button..i dont want visuforce page
ManojSankaranManojSankaran
Oh Sorry i misunderstood your question.Below is the same code to query a record and create a record using javascript. You can enhance the logic.

http://www.jitendrazaa.com/blog/salesforce/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit/
http://salesforce.stackexchange.com/questions/79533/salesforce-custom-button-onclick-javascript-create-multiple-child-record


Thanks
Manoj S
 
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);
}


}
This was selected as the best answer
nagamalli tadikondanagamalli tadikonda
hi, Hemalatha Paruchuri

i want to convert custom object into account, contact and opportunity ? cloud u please provide complete code once.
Laxmaya ChnLaxmaya Chn
Thanks!!! Hema it's working.
Raviteja A 1Raviteja A 1
@hemalatha, Can you please let us know where to keep the code that you have posted here.??