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
ovillovill 

DescribeSObjects is a SUB in VBA office toolkit!!!!!!!!!!!!!!!!

Hi,

 

Trying to get information from SObjects in order to know the last Update date information of each one, I found some issues with VBA SFDC library:

 

  1. SForceSession4.EntityNames array cannot be used as parameter to SForceSession4.DescribeSObjects because it is a Variant array. Ok, let's take the EntityNames array and construct an array of string with it. This will avoid the "Run-time error. Automation error. Unespecified error" message
  2. After fixing the previous issue, the DescribeSObjects works but, where is the description of each SObject described? 
  3. If we use the Object Browser in VBA IDE, we can see that Salesforce Toolkit 4.0, SForceSession4.DescribeSObjects  is a SUB and NOT a FUNCTION, even more, there is no DescribeSObjectResult type in the DLL that will allow us to check the description of each described object

 

Does anyone have an idea of how to use this DescribeSObjects sub?

 

Thanks!

ddddavoddddavo

Hi Ovill,

 

I've been trying to make the DescribeSObjects stuff to work at all in VBA, and I've never found any code samples that work in any way.  (see my previous posts on the topic)

 

if you can post the code snippet that you've got, I'll try to answer your question about what the contents of the DescribeSobjectResults object should look like.

 

Have you seen this page??  and this one??

ovillovill

Hi DDDD

 

I unistalled the toolkit and removed the code, but I can remember the lines that "will work"

Something like this:

 

Dim mySForceSession4 as SForceSession4

Dim myEntities(0 to 1) as String --> this was the key

 

mySForceSession4.Connect --> I cannot remember the method

 

myEntities(0) = "Account" --> API name of each object, you can take them from EntityNames actually, but cannot use EntityNames  array because it is array of Variant not array of String

myEntities(1) = "Leads"

 

mySForceSession4.DescribeSObjects (myEntities) --> THIS WORKS

mySForceSession4.DescribeSObjects (mySForceSession4.EntityNames ) --> THIS DOESN'T WORK

 

 

Regards,

O

ddddavoddddavo

ovill wrote:

Hi DDDD

 

I unistalled the toolkit and removed the code, but I can remember the lines that "will work"

Something like this:

 

Dim mySForceSession4 as SForceSession4

Dim myEntities(0 to 1) as String --> this was the key

 

mySForceSession4.Connect --> I cannot remember the method

 

myEntities(0) = "Account" --> API name of each object, you can take them from EntityNames actually, but cannot use EntityNames  array because it is array of Variant not array of String

myEntities(1) = "Leads"

 

mySForceSession4.DescribeSObjects (myEntities) --> THIS WORKS

 

WOW -- I can't get that to work -- it throws a Type Mismatch error. 

the lines I have are:

   Dim DescribeSobjectResults() As SForceOfficeToolkitLib4.SObject4

   (SFDC is my working session to the system)

   (objs() is a string array, just like what you have)

   DescribeSobjectResults = SFDC.DescribeSObjects(objs)

 

Any clue as to what you did differently to make it work?

  

mySForceSession4.DescribeSObjects (mySForceSession4.EntityNames ) --> THIS DOESN'T WORK

   yeah, that won't work.  You have to pull the DescribeSobjecdtResults() array, then go through it

   iteratively to pull out names, values, etc. 

 

 

Regards,

O




ovillovill

Hi DDDD,

 

Try with a string array with fixed length like objs(1 to 20) --> if you need more or less elements, redim the array.

Do first a test with 2 elements like I did

 

Regards,

O

ovillovill

Other thing:

 

DescribeSobjectResults = SFDC.DescribeSObjects(objs) --> will NOT work, DescribeSObjects is a SUB not a Function.

 

And that leads us to the beginning, the subject of this thread.

 

Regars,

O

ddddavoddddavo

ovill wrote:

Hi DDDD,

 

Try with a string array with fixed length like objs(1 to 20) --> if you need more or less elements, redim the array.

Do first a test with 2 elements like I did

 

Regards,

O


Hi--yes, I had a "fixed" dim array already:

 

dim objs(1 to 2) as string

ddddavoddddavo

ovill wrote:

 

              mySForceSession4.DescribeSObjects (myEntities) --> THIS WORKS

 

So what about this "works"?

Yes, you can execute it...but what indication do you have that it did anything?

 

You're absolutely right that DescribeSObjects is a sub...and we can't see much abou it.

 

I SUSPECT that what happens is you run the sub, and then look in the SForceSession4 properties like EntityNames.  So the results are presented back to you in separate arrays.  For example, if you do:

 

debug.print(mySforceSession4.CurrentServerTime) you get something

when you try

debug.print(mySforceSession4.EntityNames) you get a type mismatch error.  I suspect EntityNames is an array....and the juicy things you really want in the result set would be of the SObject4 type, not the SForceSession4 type??




 

ovillovill

DDDD,

 

Now you are in the same point I was :-)

 

Ok, where is the array/set/collection of objects retrieved by DescribeSObjects ? I don't know.

 

Probably you are right, and the variant array EntityNames contains now more data after that exec. I didn't test it. But if the name means something, the array is of Entities' name only ...

 

Assume you successfuly described Account, then try this debug.print(mySforceSession4.EntityNames("Account")).

 

If it works, GREAT! let me know please, because in Toolkit 4 that is the way. If not, I believe we have to downgrade to version 3.

 

Regards,

O

ddddavoddddavo

ovill wrote:

DDDD,

 

Now you are in the same point I was :-)

 

Ok, where is the array/set/collection of objects retrieved by DescribeSObjects ? I don't know.

 

Probably you are right, and the variant array EntityNames contains now more data after that exec. I didn't test it. But if the name means something, the array is of Entities' name only ...

 

Assume you successfuly described Account, then try this debug.print(mySforceSession4.EntityNames("Account")).

 

If it works, GREAT! let me know please, because in Toolkit 4 that is the way. If not, I believe we have to downgrade to version 3.

 

Regards,

O


Tried to debug.print

mySforceSession4.EntityNames("Account"))

mySforceSession4.EntityNames(0))

mySforceSession4.EntityNames())

and all of them failed with the same message:

    Property let procedure not defined and property get procedure did not return an object

 

Two interesting tidbits:

  - you can't do this in immediate mode, it only works in executing the sub

  - it is possible that you have to log in to SFDC using SOAP API 16, nothing newer (and this is almost certain never to change)

 

In any case, I still don't get anything useful yet.


ddddavoddddavo

"When all else fails, lower your standards..."

 

So forget about following what the documentation says about using DescribeSObjects and all that fancy schmancy API stuff.

 

Instead, just create a dummy object that you want to know about, like this, and interrogate its SObject4 properties to get what you need:

 

    Dim JunkObj As SObject4
    Set JunkObj = SFDC.CreateObject("Lead")
    Debug.Print (JunkObj.DefaultRecordTypeID)

 

For things that are more complicated than just a single value, such as the array of variable names, you have to iterate through the Names array, like this...

 

    For Each fld In JunkObj.Fields
        Debug.Print (fld.Name)
        If fld.Name = "LeadSource" Then                         ' this is an example of how you go fishing for picklist values
             For Each val In fld.PickListValues
                Debug.Print (val.Label)
             Next val
    End If
    Next fld

 

ovillovill

DDDD

 

Be carefull, the create object will provide you what you said, but I don't think it will allow you to check the current value of fields like "LastUpdate", it will be empty.

 

I remember I tried the option you are proposing, but couldn't retrive infrmation about when and who modified the object in the environment.

 

Regards,

O

richardemoorerichardemoore

Well, after a lot of tinkering, I have an imperfect solution, but it works!!! Try it yourself.

 

Public Function listFieldsInSObject()
Dim JunkObj   As SObject4
Dim SFAPI       As SForceSession4
Dim i                 As Integer  'as a counter

On Error Goto Errortrap

Set SFAPI = fnSFLogin             'fnSFLogin just logs in and returns an active session

 

Set JunkObj = SFAPI.CreateObject("objectNameHere__c")

i=0

do until i = 1000 'arbitrary, make it bigger or smaller if you want
     Debug.Print JunkObj(i).Name & " - " & JunkObj(i).ReferenceTo 'and include whatever else you want
     i = i + 1
loop

Exit Function

 

Errortrap:

  Msgbox "Welp, that failed! Or I reached the end of the field list!"

  Exit Function
End Function

CJMCCMDCJMCCMD
This worked in VB:

        Dim tempsfo As SObject4
        tempsfo = sfAPI.CreateObject("objectname__c")
        For Each fld As Object In tempsfo.Fields
            FieldList &= fld.Name & ", "
        Next