I have a created a custom button using Onclick Javascript action.

I have a custom picklist field on Opportunity; I am just checking the value selected for this field on click of this button.

If the value is X or Y or Z then it should stay in the same page with an alert message,else it should take them to a different site.

The below script works perfectly, but when I click this button on opportunities in which the opportunity name has double quotes then it throws the below error:

missing ) after argument list

e.g: " N "Third Avenue (Opportunity name)

Can anyone please assist me in trouble shooting and a workaround..


function checktype() {
if("{!Opportunity.Opportunity_Type__c}" == "X" ||
"{!Opportunity.Opportunity_Type__c}" == "Y" ||
"{!Opportunity.Opportunity_Type__c}" == "Z"
alert("Opportunity type: {!Opportunity.Opportunity_Type__c} is not supported ");



  • The redirect url contains the opportunity name, i believe that is causing the issue: window.location.replace("anothersite.com/login/…{!Opportunity.Id}&SfdcOpName={!Opportunity.Name}&SfdcServerURL={!API.Partner_Server_URL_280}&SfdcSessionID={!API.Session_ID}"); How do i overcome the double quotes character while dynamically passing the oppty name in the redirect url
    – user5352
    Commented Aug 13, 2015 at 15:14

2 Answers 2


You can use the URLENCODE function on the oppotunity name when generating the url so that it retains all those special characters properly


or you can use the javascript encodeURI function as well to get a proper url and redirect


I hope URLENCODE function will solve your issue. Can you please try replacing SfdcOpName={!Opportunity.Name} with SfdcOpName={!URLENCODE(Opportunity.Name)} and try again. Thanks.

You must log in to answer this question.

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