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
rickhugierickhugie 

JSENCODE incorrect argument type

I am trying to use JSENCODE to get away from stored XSS security flags. When I use it I get an error  "Incorrect argument type for function 'JSENCODE()'"

 

I am not sure what I am getting wront on this. When I don't use JSENCODE the value comes out but when I wrap it in JSENCODE it gives the error when saving in Eclipse.  Below is my code snippet, thanks for the help in advance.

 

function initialize() {

 

    var myOptions = {

        zoom: 8,

        mapTypeId: google.maps.MapTypeId.ROADMAP,

        mapTypeControl: false

    }

    var locLat = {!JSENCODE(Location__c.Latitude__c)};

    var locLong = {!Location__c.Longitude__c};

    var myLatlng = new google.maps.LatLng(locLat, locLong);

    var infowindow = new google.maps.InfoWindow({

        content: "<b>{!HTMLENCODE(Location__c.Name)}</b><br>" + locLat + "<br>" + locLong

    });

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

yes, jsencode requires a text parameter.   So convert with the text function:  

JSENCODE(TEXT(Location__c.Latitude__c))

All Answers

kranjankranjan
Hi Rick,

Please check the value you are passing i.e. what value is being stored in the Location__c.Latitude__c field for the record getting processed. It seems it is incorrect value.
rickhugierickhugie

Thanks for the response Kamal.  

 

There are values in Latitude__c and Longitude__c, if I don't use JSENCODE the value shows as expected. I'm wondering if it is the type of value. These are defined as Number(3, 13), do I need to convert them into text for JSENCODE to work?

 

 

aballardaballard

yes, jsencode requires a text parameter.   So convert with the text function:  

JSENCODE(TEXT(Location__c.Latitude__c))

This was selected as the best answer
rickhugierickhugie

Thank you, using TEXT function worked. 

 

also thanks for tolerating a NEWB question.