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
Shubham MirketaShubham Mirketa 

SOQL query throwing INVALID FIELD error when run through javascript

I am trying to run SOQL query on contact object through Javascript and getting all the updateble fields. But when i try to run the query, the sForce object throws an error that INVALID_FIELD: ↵OtherCountry,OtherLatitude,OtherLongitude,OtherGeocodeAccuracy,MailingStreet↵.
When i run the same query in the query editor, it runs fine and returns all the fields. But it throws error when run through javascript. There is no error in Javascript as i have removed these fields and the query worked fine.  
Sathish balajiSathish balaji
Can you please post your Javascript snippet here? And are you using Javascript Rest API toolkit or usinig directly in visualforce page?
Shubham MirketaShubham Mirketa
Thanks for replying @Sathish balaji.
This is my javascript snippet where i run the query. It is written directly on  a VF page. The variable queryfields contains the fields of the object and the object variable holds the object name. 
<apex:includeScript value="{!$Resource.Jquery_min}"/>
<apex:includeScript value="/soap/ajax/32.0/connection.js"/>
<apex:includeScript value="/soap/ajax/32.0/apex.js"/> 
   var query="select "+queryFields+" from "+object+" where id='"+recordID+"'";
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    var qr = sforce.connection.query(query);
    var records = qr.getArray("records");
Sathish balajiSathish balaji
Where are you assigning the fields into queryFields. can you post that queryField Assignment as well. Try hardcoding those fields instead of queryFields variables and give a try.
Shubham MirketaShubham Mirketa
There is a list of fields in my apex controller. I am accessing that list into my vf page. 
And i have tried hardcoding the fields. The error persists. It is throwing INVALID FIELD error on the same fields. I don't think there is any issue with the query fields.I have tested both by dynamically accessing the fields as well as hardcoding the fields. Same error is being thrown repeatedly that the fields are invalid. The issue is with the location fields only like geocodeaccuracy, lattitude, longitude etc.
Sathish balajiSathish balaji
I just tried this through SOAP API and succeeded using it but not through Javascript. however it should work same. i could not guess anything. maybe i could if i get a chnace to look into the controller and this page
Field[] f = connection.describeSObject("Position__c").getFields();
            String s = "select id,name,MailingAddress,MailingGeocodeAccuracy,OtherAddress,OtherGeocodeAccuracy,Otherlatitude from contact limit 5";
            QueryResult a = connection.query(s);
            for(SObject s1 : a.getRecords()){
            	if(s1 instanceof Contact){
            		Contact a1 = (Contact)s1;

Shubham MirketaShubham Mirketa
Thanks for the effort man. But i have to do this using javascript. My main aim was to show the details of a record to the user on click of a button. But i don't want the user to edit any fields of the record. So i had to make a seperate VF page for displaying the record. And for getting the values of the fields, i need to use javascript for running the query to get the respective fields. There are multiple records on my page and there is a view button associated with each record which opens the respective record detail page. I need to prevent the user from editing or deleting the record from there.