You need to sign in to do that
Don't have an account?
edoardo_spano
Manage sObject list in Javascript
Hi All,
I need to manage a list of Accounts with Javascript, inside a Visualforce page.
I retrieved the accounts with a SOQL query and saved the result in a public List<Account>.
When I try to assign the list at a Javascript variable, the system retrieves this error message:
Uncaught SyntaxError: Unexpected token ILLEGAL
I just tried to assign the list in this way: var accounts = {!accns};
After this assignment, I need to read an information saved in a field for each account, but I don't know how I can access at that field.
Someone can help me about these issues?
Thanks in advance
I need to manage a list of Accounts with Javascript, inside a Visualforce page.
I retrieved the accounts with a SOQL query and saved the result in a public List<Account>.
When I try to assign the list at a Javascript variable, the system retrieves this error message:
Uncaught SyntaxError: Unexpected token ILLEGAL
I just tried to assign the list in this way: var accounts = {!accns};
After this assignment, I need to read an information saved in a field for each account, but I don't know how I can access at that field.
Someone can help me about these issues?
Thanks in advance
In visualforce:
In apex controller:
Best regards!
All Answers
Then your jsAccounts array will have the account values. Now you can just loop through the array and access the field. Just try console.log(jsAccounts) to see the content of the account array. Then you will understand who you should retrieve the values
Please try to wrap your list variable in string format
for example ,
Hope this helps you !!
Cheers
in the above script we are defining an array ,and iterating over a list of account using repeat statment ,as per the javascirpt syntax inorder to push some records into array we use push method the same way we use in apex controller ,Ex:list.add(a); ,to check the ouptup use console.log('Account') , to see your ouptput .
Hope this helps you
Cheer
In visualforce:
In apex controller:
Best regards!