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
Ram ChaturvediRam Chaturvedi 

How to write Java Script SOQLwhere query ?

I am working with list view , after fetching id's i want to access that record using those id's , so what will be query .?

{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")}

var records = {!GETRECORDIDS($ObjectType.student__c)};
Kathir DevanKathir Devan
Hi Ram,

Just you have try this code:

{!RequireScript("/js/functions.js")}

var recordsSelected = {!GetRecordIds($ObjectType.student__c)}
for(var i=0; i < recordsSelected .length ; i++) {
alert('Selected ID. '+recordsSelected[i]);
}

Thanks,
kathir.
Deepak Kumar ShyoranDeepak Kumar Shyoran
Use below code by modifying this according to your need

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
var a="{!Location__c.Id}";
var strQuery="SELECT Id FROM Promo_Material_Snapshot__c where Location__c =\'"+ a + "\' limit 1";
var result = sforce.connection.query(strQuery);

Hope you'll be able to modify above code according your need.
Ram ChaturvediRam Chaturvedi
record.city__c not showing value , Why ?
  
var records = {!GETRECORDIDS($ObjectType.student__c)};
for(var i=0 ; i<records.length ; i++){
            
             var query = "SELECT city__c from student__c where id= \'"+ records[i] + "\'";
          
             var record = sforce.connection.query(query);

            alert('this is msg'+record.city__c);
}
Deepak Kumar ShyoranDeepak Kumar Shyoran
Below code is working for me, so make sure you are using Full Api name with Namespace also.

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

var strQuery="SELECT Id,Deepak_Shyoran__Age__c FROM Deepak_Shyoran__Student__c where Deepak_Shyoran__Age__c !=null limit 2";

var result = sforce.connection.query(strQuery);
var records = result.get('records') ;
console.log('----'+result);
console.log('--rec-'+records ) ;

for(var i=0 ; i<records.length ; i++){
 alert('this is msg---'+records[i].Deepak_Shyoran__Age__c );
}

As this is not working when I remove the Namespace from the Field and Object which is Deepak_Shyoran so use full name with namespace.


Ram ChaturvediRam Chaturvedi
This code also not shows value in alert :  
------------------------------------------------
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

var strQuery="SELECT Id,city__c FROM Student__c where city__c ='kota'";



var result = sforce.connection.query(strQuery);

var records = result.get('records') ;

console.log('----'+result);

console.log('--rec-'+records ) ;



for(var i=0 ; i<records.length ; i++){

alert('this is msg---'+records[i].city__c );

}

User-added image
Deepak Kumar ShyoranDeepak Kumar Shyoran
As javascript is case sensitive so make sure you using appropriate API name for City__c by consider the Capital letter and Small Letter case for API name.
Kathir DevanKathir Devan
Hi Ram,

You try this code i hope you get id....

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

var strQuery="SELECT Id,city__c FROM Candidate__c where city__c ='kota'";




{!RequireScript("/js/functions.js")}

var recordsSelected = {!GetRecordIds($ObjectType.student__c)}
for(var i=0; i < recordsSelected .length ; i++) {
alert('Selected ID. '+recordsSelected[i]);
}

Thanks,
kathir
Kathir DevanKathir Devan
Hi Ram,

Just change your object name....

Kathir DevanKathir Devan
Hi,

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}

var strQuery="SELECT Id,city__c FROM student__c where city__c ='kota'";




{!RequireScript("/js/functions.js")}

var recordsSelected = {!GetRecordIds($ObjectType.student__c)}
for(var i=0; i < recordsSelected .length ; i++) {
alert('Selected ID. '+recordsSelected[i]);
}

thanks,
kathir
Ram ChaturvediRam Chaturvedi
Thanks Mr deepak , and how can we delete a particular record using java script .
Kathir DevanKathir Devan
Hi Ram,

Which obj u want to be delete just the object name....

Code:

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}

var idsToDelete = {!GETRECORDIDS( $ObjectType.Lead)};
var deleteWarning= 'Are you sure you wish to delete ' +idsToDelete.length+ ' Records?';
if(idsToDelete.length&& (window.confirm(deleteWarning)))
{
sforce.connection.deleteIds(idsToDelete,function()
{navigateToUrl(window.location.href);
});
}
else if (idsToDelete.length == 0)
{
alert("Please select the leads you wish to delete.!!");
}

Thanks,
kathir
Ram ChaturvediRam Chaturvedi
I thing this code will delete all selected record , but i want to delete only one record on the basis on some condition .
Kathir DevanKathir Devan
HI,

Select the check box menas which record you want to delete....

Thanks