You need to sign in to do that
Don't have an account?
ElenaCapta
Hi,
length of a list
Hi,
I want to know the length of a list, I'm use the next code. Does anybody know where is the error?
Thanks and best regards
Code:<script src="http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script> <script> function initPage ( ) { sforceClient.registerInitCallback (setupPage); sforceClient.init ( "{!API_Session_ID}" , "{!API_Partner_Server_URL_70}" ); } function setupPage ( ) { cuenta ='{!Account_Name}'; var queryResult = sforceClient.query("Select Id from Opportunity where Account =' "+cuenta+" ' and StageName = 'Ganada' ", false); var e =[]; e = queryResult; alert ('Test: '+e.length); }
The exact syntax is e.size
Regards
Thanks The_Fox,
but it isn't work still, do you know the cause??
Best regards, Elena
Code:
1. An Opportunity record doesn't actually have the Account *Name* stored in the Opportunity, it has the "AccountId". This is where Salesforce is being helpful in the user interface, and displaying the Account Name for you, but it's not really there in the data.
So, The query is changed to use AccountId and {!Opportunity_Account_ID}
2. "cuenta" needs a "var".
3. The Query is also changed to remove the spaces that you used to have around cuenta.
4. You don't need to create a different array to hold the results of the query, just one. So, I removed "queryResult", and are just using "e". The important thing to remember is that "e" is not an Array. "e" is now of type "QueryResult".
5. "e" has several fields depending on the results of the query. However, if it works properly it will have an array called records that holds your data and you can use the length() function on that.
6. "e" also has a .size field, however the size may not always be the same as the length depending on other factors like the BatchSize.
7. For debugging, if you aren't getting the values you expect, you can always just display the entire queryResult by just displaying the whole variable. 'alert(e);'
The code above should work but I haven't run it. I would suggest going to the AppExchange and downloading some of the applications there. Then explore the s-controls that others have written to get a feel for how it works, how to detect the various kinds of error conditions, and how to us the different database fields.
Best of luck, Steve Bower
<html>
<head>
<script src="http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script>
function initPage ( ) {
sforceClient.registerInitCallback (setupPage);
sforceClient.init ( "{!API_Session_ID}" , "{!API_Partner_Server_URL_70}" );
}
function setupPage ( ) {
var cuentaId ='{!Opportunity_Account_ID}';
var e = sforceClient.query("Select Name from Opportunity where AccountId ='"+cuentaId+"' and StageName = 'Ganada'", false);
alert('hola');
//alert ('Test: ' + e.records.length);
// tambien
alert ('Test: ' + e.size);
//alert(e);
}
</script>
</head>
</html>
<body onload="initPage()">
</body>
Message Edited by ElenaCapta on 07-18-2006 09:32 AM
Message Edited by The_Fox on 07-19-2006 09:15 AM
Thanks to all!!!
Now it's work OK!
Thanks for all and best regards!:smileywink: