You need to sign in to do that
Don't have an account?
ovill
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:
- 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
- After fixing the previous issue, the DescribeSObjects works but, where is the description of each SObject described?
- 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!
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??
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
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
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
Hi--yes, I had a "fixed" dim array already:
dim objs(1 to 2) as string
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.
"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
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
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
Dim tempsfo As SObject4
tempsfo = sfAPI.CreateObject("objectname__c")
For Each fld As Object In tempsfo.Fields
FieldList &= fld.Name & ", "
Next