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
bheemudu neelibheemudu neeli 

My text have (`) so now how to avoid this quote by java script.

acutally i am getting Unexpected identifier error. I found the resone, In my text data have the (`), so that I'm getting, I can't change the data in Production, so I want to solve it by java script. first is it possible? 
advance thanks, 

 
Best Answer chosen by bheemudu neeli
SonamSonam (Salesforce Developers) 
Ok so if I understand this correctly, you are concerned about the merge field values that might contain ' right? if yes, you should be using JSENCODE as shown below when using merge fields:

"{!JSENCODE(mergeField)}";
e.g.
 "{!JSENCODE(Object__c.Field)}";
 

All Answers

SonamSonam (Salesforce Developers) 
You should be using JSENCODE to avoid any special characters in the merge field values:

JSENCODE
Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe (').

usage :{!JSENCODE(text)} and replace  text with the merge field or text string that contains the unsafe JavaScript characters.

reference:
http://www.salesforce.com/docs/developer/pages/Content/pages_variables_functions.htm
bheemudu neelibheemudu neeli
Hello Sonam,
I tried your suggestion,and some alternate ways. but I want eliminate the special chars by javascript.

Here is the my original code.
.................................
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}

var result =sforce.connection.query("select Order_confirmation_email__c from Account where id='{!Account.AccountId__c}'");
records = result.getArray("records");

var billtoparty='{!Account.Default_Bill_to_party__c}';
var corderemail='{!Account.Order_confirmation_email__c}';
var worderemail=''
var custEmail='';
var wholesaleEmail='';
var billtoPartyVal='';
var billtoPartyId='';
if(records[0])
{
worderemail=result.records.Order_confirmation_email__c;
}
if(billtoparty.length!=0)
{
billtoPartyVal='{!Account.Default_Bill_to_party__c}';
billtoPartyId='{!Account.Default_Bill_to_partyId__c}';
}
else
{
billtoPartyVal='{!Account.Name}';
billtoPartyId='{!Account.Id}';
}

if(corderemail.length!=0)
{
custEmail=corderemail;
}
else
{
custEmail='{!Account.Email_Address__c}';
}

if(worderemail!=null)
{
wholesaleEmail=worderemail;
}
else
{
wholesaleEmail='{!Account.Wholesaler_Email_Address__c}';
}
var url='/setup/ui/recordtypeselect.jsp?ent=01I20000000SUSG&retURL=%2Fa07%2Fo&save_new_url=%2Fa07%2Fe%3FretURL%3D%252Fa07%252Fo';
url+='&CF00N20000009GubC={!Account.Name}';
url+='&CF00N20000009GubC_lkid={!Account.Id}';
url+='&CF00N20000009GucF={!Account.Account__c}&CF00N20000009GucF_lkid={!Account.AccountId__c}';
url+='&CF00N11000000tp0l='+billtoPartyVal+'&CF00N11000000tp0l_lkid='+billtoPartyId;
url+='&CF00N11000000tp15={!Account.Name}&CF00N11000000tp15_lkid={!Account.Id}';
url+='&CF00N11000000l4FO={!Account.Default_Sales_Org__c}&CF00N11000000l4FO_lkid={!Account.Default_Sales_OrgId__c}';
url+='&00N11000000sfk3='+custEmail+'&00N11000000sfje='+wholesaleEmail;
window.parent.open(url, "_self");
..................................
SonamSonam (Salesforce Developers) 
Ok so if I understand this correctly, you are concerned about the merge field values that might contain ' right? if yes, you should be using JSENCODE as shown below when using merge fields:

"{!JSENCODE(mergeField)}";
e.g.
 "{!JSENCODE(Object__c.Field)}";
 
This was selected as the best answer
bheemudu neelibheemudu neeli
Thanks Sonam, it works awesome.