+ Start a Discussion
RogerHandRogerHand 

Flex toolkit R3.1: DescribeSObjectResult.fields always empty

I am using Flex toolkit version R3.1 and am never seeing anything in the describeSObjectResult.fields property for either a native or custom object. Other properties show up fine but the fields property, while not null, always has a length of 0.
 
Also, the ObjectUtil.toString() utility function shows the fields.
 
Code:
private function describeSObjectsSample():void {
  
  apex.describeSObjects(["Contact", "KAILEA__change__c"], 
      new AsyncResponder(describeSObjects2, genericFault));
}
    
private function describeSObjects2(describeSObjectResults:Array):void {
  for (var i:int=0; i<describeSObjectResults.length; i++) {
    describeSObject2(describeSObjectResults[i]);
  }
}    
          
private function describeSObject2(describeSObjectResult:DescribeSObjectResult):void {
  var objectName:String = describeSObjectResult.name;

  Alert.show("Object name: " + objectName
    + ", createable: " + describeSObjectResult.createable
    + ", queryable: " + describeSObjectResult.queryable
    + ", updateable: " + describeSObjectResult.updateable
    + ", custom: " + describeSObjectResult.custom
    );

  Alert.show("toString(): " + ObjectUtil.toString(describeSObjectResult));

    var fields:Array = describeSObjectResult.fields;
    Alert.show("describeSObject2() have fields? " + (fields != null));
    Alert.show("describeSObject2() fields.length: " + fields.length);
    for (var f:int=0; f<fields.length; f++) {
      var field:Field = fields[f];
      Alert.show("field: " + field.name);
    } // next field
}

 
Thanks in advance for any help!
 
-Roger
RogerHandRogerHand
I tried again with version R3.2 with the same results.
Ron HessRon Hess
Question, this works with the salesforce.mxml sample but fails with your code?

Or is it failing with the sample of describeSObjects?

here is the output of describesobjects on my system, fields array appears to be filled in with info:
(some content deleted to allow a post...)

Code:
describeSObjects_CB Result
(Array)#0
  [0] (com.salesforce.results::DescribeSObjectResult)#1
    activateable = false
    childRelationships = (Array)#2
      [AccountContactRoles] (com.salesforce.results::ChildRelationship)#3
        cascadeDelete = true
        childSObject = "AccountContactRole"
        field = "AccountId"
        relationshipName = "AccountContactRoles"

 createable = true custom = false deletable = true fields = (Array)#25 [AccountNumber] (com.salesforce.results::Field)#26 autoNumber = false byteLength = 120 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Account Number" length = 40 name = "AccountNumber" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "string" unique = false updateable = true [Active__c] (com.salesforce.results::Field)#27 autoNumber = false byteLength = 765 calculated = false caseSensitive = false createable = true custom = true defaultedOnCreate = false digits = "0" filterable = true label = "Active" length = 255 name = "Active__c" nameField = false namePointing = false nillable = true picklistValues = (mx.collections::ArrayCollection)#28 filterFunction = (null) length = 2 list = (mx.collections::ArrayList)#29 length = 2 source = (Array)#30 [0] (com.salesforce.results::PickListEntry)#31 active = true defaultValue = false label = "No" value = "No" [1] (com.salesforce.results::PickListEntry)#32 active = true defaultValue = false label = "Yes" value = "Yes" uid = "286D097D-35D1-14AE-3C70-F2F45780A143" sort = (null) source = (Array)#30 precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "picklist" unique = false updateable = true [AnnualRevenue] (com.salesforce.results::Field)#33 autoNumber = false byteLength = "0" calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Annual Revenue" length = 0 name = "AnnualRevenue" nameField = false namePointing = false nillable = true picklistValues = (null) precision = 18 referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:double" sortable = true type = "currency" unique = false updateable = true [BillingCity] (com.salesforce.results::Field)#34 autoNumber = false byteLength = 120 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Billing City" length = 40 name = "BillingCity" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "string" unique = false updateable = true [BillingCountry] (com.salesforce.results::Field)#35 autoNumber = false byteLength = 120 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Billing Country" length = 40 name = "BillingCountry" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "string" unique = false updateable = true [BillingPostalCode] (com.salesforce.results::Field)#36 autoNumber = false byteLength = 60 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Billing Zip/Postal Code" length = 20 name = "BillingPostalCode" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "string" unique = false updateable = true [BillingState] (com.salesforce.results::Field)#37 autoNumber = false byteLength = 60 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Billing State/Province" length = 20 name = "BillingState" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "string" unique = false updateable = true [BillingStreet] (com.salesforce.results::Field)#38 autoNumber = false byteLength = 765 calculated = false caseSensitive = false createable = true custom = false defaultedOnCreate = false digits = "0" filterable = true label = "Billing Street" length = 255 name = "BillingStreet" nameField = false namePointing = false nillable = true picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "textarea" unique = false updateable = true [CreatedById] (com.salesforce.results::Field)#39 autoNumber = false byteLength = 18 calculated = false caseSensitive = false createable = false custom = false defaultedOnCreate = true digits = "0" filterable = true label = "Created By ID" length = 18 name = "CreatedById" nameField = false namePointing = false nillable = false picklistValues = (null) precision = "0" referenceTo = "User" relationshipName = "CreatedBy" restrictedPicklist = false scale = "0" soapType = "tns:ID" sortable = true type = "reference" unique = false updateable = false [CreatedDate] (com.salesforce.results::Field)#40 autoNumber = false byteLength = "0" calculated = false caseSensitive = false createable = false custom = false defaultedOnCreate = true digits = "0" filterable = true label = "Created Date" length = 0 name = "CreatedDate" nameField = false namePointing = false nillable = false picklistValues = (null) precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:dateTime" sortable = true type = "datetime" unique = false updateable = false [CustomerPriority__c] (com.salesforce.results::Field)#41 autoNumber = false byteLength = 765 calculated = false caseSensitive = false createable = true custom = true defaultedOnCreate = false digits = "0" filterable = true label = "Customer Priority" length = 255 name = "CustomerPriority__c" nameField = false namePointing = false nillable = true picklistValues = (mx.collections::ArrayCollection)#42 filterFunction = (null) length = 3 list = (mx.collections::ArrayList)#43 length = 3 source = (Array)#44 [0] (com.salesforce.results::PickListEntry)#45 active = true defaultValue = false label = "Medium" value = "Medium" [1] (com.salesforce.results::PickListEntry)#46 active = true defaultValue = false label = "Low" value = "Low" [2] (com.salesforce.results::PickListEntry)#47 active = true defaultValue = false label = "High" value = "High" uid = "7C75AA75-5D6D-18CE-1BE0-F2F4577E3DDD" sort = (null) source = (Array)#44 precision = "0" referenceTo = (null) restrictedPicklist = false scale = "0" soapType = "xsd:string" sortable = true type = "picklist" unique = false updateable = true keyPrefix = "001" label = "Account" labelPlural = "Accounts" layoutable = true mergeable = true name = "Account" queryable = true recordTypeInfos = (Array)#152 [Master] (com.salesforce.results::RecordTypeInfo)#153 available = true defaultRecordTypeMapping = true name = "Master" recordTypeId = "012000000000000AAA" replicateable = true retrieveable = true searchable = true undeletable = true updateable = true urlDetail = "https://na1.salesforce.com/{ID}" urlEdit = "https://na1.salesforce.com/{ID}/e" urlNew = "https://na1.salesforce.com/001/e" [context] (null)

 

RogerHandRogerHand

The output you pasted appears to be from the Macromedia ObjectUtil.toString() function. As I mentioned in my post, this does work to show the fields.

However, the fields are not available by accessing the DescribeSObjectResult.fields property.

I started with the R3.4 salesforce.mxml example and changed the describeSObjects() function to call this new function in it's AsyncResponder:

Code:

private function describeSObjects_Test(result:Object):void
{
 if (result.length > 0) {
  var describeSObjectResult:DescribeSObjectResult = result[0];
  //ta.text = 'describeSObjects_Test Result\n' + describeSObjectResult;
  ta.text = 'describeSObjects_Test describeSObjectResult.fields = \n' + describeSObjectResult.fields.length;
 } else {
  ta.text = 'No result';
 }
}


 The result is always 0.

-Roger

Ron HessRon Hess
found this, associative arrays have length == 0 ( apperantly)

Associative arrays

Associative arrays, which are sometimes called hashes or maps, use keys instead of a numeric index to organize stored values. Each key in an associative array is a unique string that is used to access a stored value. An associative array is an instance of the Object class, which means that each key corresponds to a property name. Associative arrays are unordered collections of key and value pairs. Your code should not expect the keys of an associative array to be in a specific order.


---------

here is how you can traverse the fields array.
Code:
   private function describeSObjects_CB(result:Object):void
   {
    ta.text = 'describeSObjects_CB Result\n' ; //+ ObjectUtil.toString(result);
   if (result.length > 0) { 
    var describeSObjectResult:DescribeSObjectResult = result[0];
    //ta.text = 'describeSObjects_Test Result\n' + describeSObjectResult;
    
    for (var fld_name:String in describeSObjectResult.fields ) { 
     ta.text += 'field = ' + describeSObjectResult.fields[fld_name].name + '\n';
    }
   }
   }

 

length would be valid for an array that had ary[0], ary[1], ary[2] etc, but not for associative arrays which are indexed by strings
 
can't explain it, had me confused also.

Message Edited by Ron Hess on 06-06-2007 01:51 PM

RogerHandRogerHand

Thanks! That did it!

ECMAscript seems to be even weirder than I thought ... !

-Roger

 

swathiswathi

Hi,

 

I am trying for the same solutions can you give me the code I am just getting any describeSObjects_CB Result\n.

 

I am not getting any fields in that. Please help me out its very urgent