Uncaught SyntaxError: Unexpected identifier because of special characters and foreign language names present in Account
 I have developed page with autoComplete feature. I'm getting an Uncaught SyntaxError: Unexpected identifier error because of symbols used in Account Names such as "诸城金盛-abc Commerce and" Co., Ltd. I'm posting my code for reference.
Visualforce page Code:
|
Apex Code:
public class SFI_AccountExtension { public Account accountRecord { get; set; } public List < String> accList { get; set; } public String selectedAccount{ get; set; } public SFI_AccountExtension(ApexPages.StandardController sc) { selectedAccount = ''; accountRecord = (Account) sc.getRecord(); getAccountList();//method to load list of accounts } //Method to supply list of account with the record type name 'SAP Sold-To Customer' present in salesforce for auto complete public List < String> getAccountList() { accList = new List < String> (); Id RecordTypeId = [SELECT Id, Name FROM RecordType WHERE SobjectType = 'Account' AND Name = 'SAP Sold-To Customer' limit 1 ].id; for (Account acc: [select name, SAP_Customer_Number__c from Account where recordTypeId =: RecordTypeId]) { accList.add('"' + acc.SAP_Customer_Number__c + ' - ' + acc.name + '"'); } return accList; } }
Why getting syntaxerror: unexpected identifier? Can somebody please tell how to avoid this type of error.
Uncaught SyntaxError: Unexpected identifier. One of the most common reasons is that you're trying to mutate (change) a const variable.
It sounds like you'll need to encode your data:
var available tags = JSON.parse("{!JSENCODE(accList)}");
This may still result in errors, but it should be closer to what you're looking for.