function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranadheer chRanadheer ch 

I created a javascript button and passing Account ID and calling apex classes ...

I created a javascript button and passing Account ID and calling apex classes .When i click on button on account detail page am getting the Error when i press that button like  "A Problem with this button or link was Encountered       Unexpected Identifier"  


Button:


{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

if({!Account.Name}!=Null) 

sforce.apex.execute("SandvineCreateUpdateSAPAccount","createupdateSAPAccount",{!Account.Id}"}); 
alert("This is {!Account.Name}"); 
}



Why am getting this error ...this button send the account ID to the external URL
Best Answer chosen by Ranadheer ch
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Ranadheer ch:

 Try the below code:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
alert('hi');
if('{!Account.Name}'!= null) 

alert('hello');
var AccountId='{!Account.Id}';
sforce.apex.execute("SandvineCreateUpdateSAPAccount","createupdateSAPAccount",{AccountId: AccountId}); 
}


Note: The text in bold and italic "AccountId" is assumed as the parameter name you declared for method createupdateSAPAccount., like:

webservice  static void createupdateSAPAccount(Id AccountId)

So if you have any other variable name over there is method specify it in the highlighted area.

All the merge fields should be in quotes, and for usage of sforce.apex.execute statement please refer to below link:

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm

If it anwers your question, please to vote this as Best Answer.

Hope it helps:


Thanks,
Balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Ranadheer ch:

 Try the below code:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 
alert('hi');
if('{!Account.Name}'!= null) 

alert('hello');
var AccountId='{!Account.Id}';
sforce.apex.execute("SandvineCreateUpdateSAPAccount","createupdateSAPAccount",{AccountId: AccountId}); 
}


Note: The text in bold and italic "AccountId" is assumed as the parameter name you declared for method createupdateSAPAccount., like:

webservice  static void createupdateSAPAccount(Id AccountId)

So if you have any other variable name over there is method specify it in the highlighted area.

All the merge fields should be in quotes, and for usage of sforce.apex.execute statement please refer to below link:

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm

If it anwers your question, please to vote this as Best Answer.

Hope it helps:


Thanks,
Balaji
This was selected as the best answer
Ranadheer chRanadheer ch
Thanks Balaji ...It Helped me a lot