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
Maheshh PatelMaheshh Patel 

How to pass List<sobject > as parameter to Javascript function?

Hi,

I want to pass the  List<sobject> as parameter to javascript function.
I want to perfom this on Onclick action,I tried passing the parameter's normally but the function is not getting invoked.
kindly help me on how to pass list<sobject> as param to js function?


Thanks,
Mahesh Patel
Vasani ParthVasani Parth
Try below the untested code,
<apex:page controller="javascriptLearning">
<script>
    alert('{!lstAssignToArray}');
    var myList = new Array();
    myList = '{!lstAssignToArray}';
    alert(myList);
</script>
</apex:page>
 
Apex Controller:
 
public with sharing class javascriptLearning {
    public List<String> lstAssignToArray    {get;set;}
    
    public javascriptLearning()
    {
        lstAssignToArray = new List<String>();
        lstAssignToArray.add('ABC');
        lstAssignToArray.add('DEF');
        lstAssignToArray.add('GHI');
        lstAssignToArray.add('JKL');
        lstAssignToArray.add('MNO');
        lstAssignToArray.add('PQR');
        lstAssignToArray.add('STU');
        lstAssignToArray.add('VWX');
        lstAssignToArray.add('YZ');
    }
}
Please mark this as the best answer if this helps