1

When I use the JSENCODE I have the following issue:

var accRegNumber = "{!Account.Registration_Number__c}";
var accName = "{!Account.Name}";
var accType = "{!Account.Custom_Filed_Type__c}";
var accRate = "{!Account.Custom_Filed_Rate__c}";
var accId = "{!Account.Id}";

accRegNumber = {!JSENCODE(accRegNumber)};
accName = {!JSENCODE(accName)};
accType = {!JSENCODE(accType)};
accRate = {!JSENCODE(accRate)};
accId = {!JSENCODE(accId)};

Error: Field accRegNumber does not exist. Check spelling.

Could you please advise why adding {!JSENCODE(accRegNumber)}; to accRegNumber variable is giving an error message?

5

accRegNumber is a JavaScript variable. The Salesforce formula expression {!JSENCODE(accRegNumber)} is processed by the server long before the content reaches the JavaScript parser, and the server doesn't know anything about the JavaScript variables you're creating.

You need to write the formula as part of the original assignment:

var accRegNumber = "{!JSENCODE(Account.Registration_Number__c)}";
  • Wowie, thats good catch, I never found any documentation for this – Pranay Jaiswal Dec 3 '18 at 14:21

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.