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
Kalle KalifKalle Kalif 

How to get array using ajax?

I want to have an array like this : 

 

var locations =[

['blabla', 12, -13.1],

['blabla again', -3.4, 150],

['asdf', 3.2, 0]

];

 

How do i use the below ajax toolkit connection to make such an array? Because what i am trying is  not working.

 

 

var records = sforce.connection.query("SELECT LatDecimal__c, LonDecimal__c FROM Report__c ORDER BY Report_Date__c LIMIT 2");

var locations = records.getArray("locations");

//???

 

Edit: typo.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

try the code below:

var records = sforce.connection.query("SELECT Name, Id from account LIMIT 2");
var locations = records.getArray("records");
alert(locations);

 hope it helps.

All Answers

Rahul SharmaRahul Sharma

try the code below:

var records = sforce.connection.query("SELECT Name, Id from account LIMIT 2");
var locations = records.getArray("records");
alert(locations);

 hope it helps.

This was selected as the best answer
Kalle KalifKalle Kalif

my god that is the simplest thing, must also be the only thing in the world i hadnt tried. :smileysad:

 

THANK you!

eugene_bmeugene_bm

Can you please help me with this?

 

I have my java script in Static Resource.

 

function getContactId(url){
                var Pos1 = url.indexOf('salesforce.com/');
                var Pos2 = url.indexOf('/e',Pos1+1);
                var ConId = url.substring(Pos1+15,Pos2);

  var strQuery = '';               
  strQuery = "Select MailingCity, MailingCountry, MailingPostalCode, MailingState, MailingStreet from Contact where Id ='" + ConId  + "'";

  alert(strQuery); I have result here

 

  var Res = sforce.connection.query(strQuery);
  var Result = Res.getArray("records");

  var cCity = Result[0].MailingCity;
  var cCountry = Result[0].MailingCountry;
  var cPostal = Result[0].MailingPostalCode;
  var cState = Result[0].MailingState;
  var cStreet = Result[0].MailingStreet;
  
  alert(cCity);I dont have result here
  alert(cCountry);I dont have result here
  alert(cPostal);I dont have result here
  alert(cState);I dont have result here
  alert(cStreet);I dont have result here

 

}