1

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:

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
var act = new sforce.SObject("Account");
act.Name = {!Contact.Name };
act.Phone = {!Contact.Phone};
act.Type = "Personal";
var result = sforce.connection.create([act]);
if(result[0].getBoolean("success")){
window.location = "/" + result[0].id + "/e";
}else{
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!

2

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.)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.