I'm trying to do a button to my contacts that when pressed, it will automatically create a account with the contact fields. I have the next code:

var act = new sforce.SObject("Account");
act.Name = {!Contact.Name };
act.Phone = {!Contact.Phone};
act.Type = "Personal";
var result = sforce.connection.create([act]);
window.location = "/" + result[0].id + "/e";
alert('Could not create record '+result);

But it give me the error "A problem with the OnClick JavaScript for this button or link was encountered: Unexpected identifier", and I'm out of ideas. Any suggestion? Thanks!

1 Answer 1


One problem is that you need to ensure that the merge fields are interpreted as JavaScript strings by adding quotes:

act.Name = "{!Contact.Name }";
act.Phone = "{!Contact.Phone}";

(Its worth using "View Source" in the generated page to check the output and ensure it looks like valid JavaScript.)

  • Oh god, how could I missed that?! Solved! Thanks a lot!
    – danielpm
    Nov 17, 2014 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .