You need to sign in to do that
Don't have an account?
Custom Button to Convert Contact to Person Account
Hello All,
I've been assigned the task of creating a custom button on the Contact object to automagically convert Contacts to Person Accounts. I came across a great post online here:
http://www.x2od.com/2008/08/19/convert-between-business-and-person-accounts-b2b-b2c#comment-70797
... which seems like the direction I need to go. I did create the custom button to execute Java - here's the code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var ContactObj = new sforce.SObject("Account");
ContactObj.Id = '{!Account.Id}';
ContactObj.RecordTypeId = '0120000000099Lo';
sforce.connection.update([ContactObj]);
location.reload(true);
No syntax errors, created the button, put it on the Contact layout, created a test Contact, hit the button ... and ... zippo; nothing happens, not even an error message.
Anyone have a clue what I might be missing?
Thanks!
I've been assigned the task of creating a custom button on the Contact object to automagically convert Contacts to Person Accounts. I came across a great post online here:
http://www.x2od.com/2008/08/19/convert-between-business-and-person-accounts-b2b-b2c#comment-70797
... which seems like the direction I need to go. I did create the custom button to execute Java - here's the code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var ContactObj = new sforce.SObject("Account");
ContactObj.Id = '{!Account.Id}';
ContactObj.RecordTypeId = '0120000000099Lo';
sforce.connection.update([ContactObj]);
location.reload(true);
No syntax errors, created the button, put it on the Contact layout, created a test Contact, hit the button ... and ... zippo; nothing happens, not even an error message.
Anyone have a clue what I might be missing?
Thanks!
JavaScript for Custom Button to create a Person Account from a Contact:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var AccountObj = new sforce.SObject("Account");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Person Account\' limit 1");
var records = result.getArray("records");
AccountObj.RecordTypeId = records[0].Id;
AccountObj.LastName= "{!Contact.LastName}";
AccountObj.FirstName= "{!Contact.FirstName}";
res = sforce.connection.create([AccountObj]);
window.open('/'+res[0].id);
JavaScript for Custom Button to create a Contact from a Person Account:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var ContactObj = new sforce.SObject("Contact");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Contact\' limit 1");
var records = result.getArray("records");
ContactObj.RecordTypeId = records[0].Id;
ContactObj.FirstName= "{!Account.FirstName}";
ContactObj.LastName= "{!Account.LastName}";
res = sforce.connection.create([ContactObj]);
window.open('/'+res[0].id);
All Answers
If you still don't find working the you can put alert(); always.
Thanks
Ashwani
1. Never use hard coded ids in your code.
2.If you creating a person account in that case you have to copy all values of Contact to new account object and then have to perform create operation instead of update because person account is a contact but still it is an Account. So you have to create a object of Account not contact.
Try below code and here I have only considered "Name" field but you have to copy other fields too in same way.
Created the Custom Button to convert a Contact to a Person Account, which is working. Here's the final code for that:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var AccountObj = new sforce.SObject("Account");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Person Account\' limit 1");
var records = result.getArray("records");
AccountObj.RecordTypeId = records[0].Id; AccountObj.LastName= "{!Contact.LastName}";
AccountObj.FirstName= "{!Contact.FirstName}";
res = sforce.connection.create([AccountObj]);
window.open('/'+res[0].id);
Now, I want to go the other way - Person Account to Contact:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var ContactObj = new sforce.SObject("Contact");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Contact\' limit 1");
var records = result.getArray("records");
ContactObj.RecordTypeId = records[0].Id;
ContactObj.FirstName= "{!Account.FirstName}";
ContactObj.LastName= "{!Account.LastName}";
res = sforce.connection.create([ContactObj]); window.open('/'+res[0].id);
... but receive this message when I test the button to convert a Person Account to a Contact:
"Cannot read property 'Id' of undefined"
Hmmm ....
JavaScript for Custom Button to create a Person Account from a Contact:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var AccountObj = new sforce.SObject("Account");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Person Account\' limit 1");
var records = result.getArray("records");
AccountObj.RecordTypeId = records[0].Id;
AccountObj.LastName= "{!Contact.LastName}";
AccountObj.FirstName= "{!Contact.FirstName}";
res = sforce.connection.create([AccountObj]);
window.open('/'+res[0].id);
JavaScript for Custom Button to create a Contact from a Person Account:
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var ContactObj = new sforce.SObject("Contact");
result = sforce.connection.query("Select r.Name, r.IsActive, r.Id From RecordType r where r.Name = \'Contact\' limit 1");
var records = result.getArray("records");
ContactObj.RecordTypeId = records[0].Id;
ContactObj.FirstName= "{!Account.FirstName}";
ContactObj.LastName= "{!Account.LastName}";
res = sforce.connection.create([ContactObj]);
window.open('/'+res[0].id);