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
BLBL 

Flex Toolkit - DescribeSObjectResult

I'm trying to get at the childRelationships from the result of a describeSObject call using the Flex Toolkit's as3Salesforce.swc.

Trying something simple such as:

Code:
result.childRelationships

will return "undefined", rather than the array of childRelationship objects as one would expect.

For example, this code is straight from salesforce.mxml with one minor change:
Code:
   private function describeSObjects():void
   {
    // this call can take one or more object names to describe in full
    apex.describeSObjects(
    // ["Account","Contact"], 
     ["Account"], 
      new AsyncResponder(describeSObjects_CB, genericFault));
   }
   private function describeSObjects_CB(result:Object):void
   {
    ta.text = 'describeSObjects_CB Result\n' + ObjectUtil.toString(result.childRelationships);
   }

The only thing I've changed is the last parameter from "result" to "result.childRelationships". Am I wrong in expecting that this should pretty print the childRelationships from the result of the describeSObject call against the Account object?

ObjectUtil's pretty print method, toString(), will happily print out the "result" variable above, but trying to actually access the "result" variable as if it were DescribeSObjectResult class object is completely fruitless. Asking for result.childRelationships.length will return a logical result, the number of elements in the childRelationships array, but trying to access one of those elements with something like:

Code:
result.childRelationships[0]

will simply return "undefined".

Anyone else having this problem? Any suggestions on what I'm doing wrong?

For reference the Salesforce Flex Toolkit can be downloaded from here: http://wiki.apexdevnet.com/index.php/Members:Flex_Toolkit_download

Thanks,

Ben Lam


Ron HessRon Hess
I can understand your confusion, i think there is an easy answer

result is an array, so you need to access this as

result[0].childRelationships


private function describeSObjects_CB(result:Object):void
{
ta.text = 'describeSObjects_CB Result\n' + ObjectUtil.toString(result[0].childRelationships);
}
BLBL
Hi Ron,

Many thanks for your response.  If we take our example to the next step by trying to access the childRelationships array as follows:
Code:
private function describeSObjects_CB(result:Object):void
   {
    ta.text = 'describeSObjects_CB Result\n' + ObjectUtil.toString(result[0].childRelationships[0]);
   }

I'd expect that the pretty print would return the results of result[0].childRelationship[0] as information about the first childRelationship of the Account object.  But, instead it returns "undefined".

After mucking around for quite some time, I've discovered the reason for this.  "childRelationships" is not simply an array.  It's an associative array and thus has no numbered index.  This leads to the next question:

Is there a way to easily get all the keys in an associative array in ActionScript 3?  Or is there one available already in the childRelationships associate array object, but I simply don't know about it.

Thanks,

Ben Lam

ps. I don't suppose Salesforce wouldn't be interested in releasing the source code for as3salesforce.swc, would they? Having that would answer a lot of my development questions.
Ron HessRon Hess
adobe flex help on associative arrays

Iterating with object keys

You can iterate through the contents of a Dictionary object with either a for..in loop or a for each..in loop.
A for..in loop allows you to iterate based on the keys, whereas a for each..in loop allows you to iterate based on the values associated with each key Use the for..in loop for direct access to the object keys of a Dictionary object.

You can also access the values of the Dictionary object with the property access ([]) operator.

The following code uses the previous example of the groupMap dictionary to show how to iterate through a Dictionary object with the for..in loop: Use the for each..in loop for direct access to the values of a Dictionary object.

The second following code also uses the groupMap dictionary to show how to iterate through a Dictionary object with the for each..in loop:

Code:
for (var key:Object in groupMap)
{
    trace(key, groupMap[key]);
}
/* output:
[object Sprite] [object Object]
[object Sprite] [object Object]
[object Sprite] [object Object]
*/


for each (var item:Object in groupMap)
{
    trace(item);
}
/* output:
[object Object]
[object Object]
[object Object]
*/
 
All of the source code is open source, find it on source forge,

 sforce . svn .sourceforge. net / viewvc / sforce / mavericks
http://sforce.svn.sourceforge.net/viewvc/sforce/mavericks/



enjoy!


Message Edited by Ron Hess on 03-04-2008 12:29 PM