I have a VFP that read a web service to get positions, this positions send to js as array, in sandbox environment works well but when I make the implementation to production environment the arrays are null, do you have any workarround for this?

This is my code in the controller:

public transient List<Decimal> lats {get;set;}
public transient List<Decimal> lngs {get;set;}

public void getPositions(){
    for(Integer i=0; i<nPositions.size(); i++){
          system.debug('#### ' + nPositions.get(i));

This is the JS code

<script type="text/javascript">
    var lats = new Array();
    var lngs = new Array();
    function getP(){
        var latis = '{!lats}';
        var res = latis.substr(1,latis.length-2);
        lats = res.split(', ');

        var lngis = '{!lngs}';
        var res = lngis.substr(1,lngis.length-2);
        lngs = res.split(', ');
  • 1
    Hi Angello - it's going to be virtually impossible to answer this question without specifics. Can you start with a code example showing how you obtain and utilize this data, and show us how you've tried to debug it? – David Reed Jan 26 '19 at 23:43
  • Hi @DavidReed, thanks for you reply, I just added the code, as I said this is working in sandbox, but is not working in production – Angello Camacho Jan 27 '19 at 2:40
  • transient means that the values are cleared/removed from the view state. If you do not call getPositions during every single action, and the script is rerendered, this would be one possible cause. You're going to need to more debugging and/or add more code from both your page and controller here. There's simply too many variables here. – sfdcfox Jan 27 '19 at 4:47
  • Hi @sfdcfox, thanks for you reply, I understand but as I said this is working in sandbox. – Angello Camacho Jan 27 '19 at 14:40

Tentatively, I think the following adjustments should work.

Use Separate Getters

Since you're trying to use transient lists, some simple getters would work better. In Visualforce, a function named getX can be merged directly into the page via the merge field {!X} (i.e. the merge field looks for a function with get prepended to the merge field).

Direct Script Injection

Also, you don't need to parse the values directly, as you can safely insert the code directly into the script. Note that this is only safe for types like Boolean and Decimal, while String should be encoded and parsed for safety. See following example:

var firstName = "{!JSENCODE(Contact.FirstName)}"; // make the value safe.

Applying the above concepts, here's a possible alternative to your original code.


public Decimal[] getLats() {
  Decimal[] values = new Decimal[0];
  // change nPosition to correct data type
  for(nPosition position: nPositions) {
  return values;
public Decimal[] getLngs() {
  Decimal[] values = new Decimal[0];
  // change nPosition to correct data type
  for(nPosition position: nPositions) {
  return values;


var lats = {!lats};
var lngs = {!lngs};

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.