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

No RecordTypeId field???

I'm trying to insert records inside a custom object using office toolkit 3 from excel vba. Now, when I try to modify the field MyObject(0)("RecordTypeId") = newId, execution stops and I get this error message from vba:
Run-time error '-2147467259 (80004005)':
Invalid field index::recordtypeid
Then I added a watch on MyObject to see its list of fields, everything OK but RecordTypeId wasn't on the list...
I checked in the Salesforce interface to check if this field was actually created inside the object: it was!... it's a standard field inside my custom object.
I read the docs, and here is what they (api7 as well as office3) say about the RecordTypeId field:
"RecordTypeId Fields

Record types are used to offer different business processes and subsets of picklist values to different Users based on their Profile settings.

Record types are configured in the Salesforce user interface. The RecordType object is read-only in the API. A client application can retrieve the list of valid record type IDs (String) for a given object by calling Query on the RecordType object.

The RecordTypeId field can contain the ID of the RecordType that is associated with a standard or custom object. Client applications can set this field in Create or Update calls. If specified in a Create or Update call, the record type ID (String) must refer to a valid record type for that object.

:: Note

The RecordTypeId field is available only if at least one record type is configured for your organization in the Salesforce user interface.

For more information about ID fields, see ID Fields".

It actually states that it is possible to set this field in Create or Update calls using the API...

Now, why is it then that there is no RecordTypeId field accesible for me? What am I doing wrong? Am I using the wrong api (API 6.0, I suppose).  What is the meaning of the Note above: how can I configure at least one record type for my organization in the Salesforce user interface?????

Help very much appreciated!

Best regards, Santiago

The note means that for the Record Type ID field to be necessary you must first create at least one Record Type for your custom object.
To do this, select Setup > Build > Custom Objects then select the object you are working with.  On the detail page for that object is a related list for Record Types. 
If your custom object does not have any record types then you can elimnate that field from your insert/updates.

Hi bouscal, thank you for your reply!

I did what you told me to do and found that there actually is a list of custom record types listed at the bottom of the detail page for my custom object... The custom object is named Service, and the listed custom record types include "Long Distance", "Data", and a few more.

The default record type for the Service object is "Data". But what I want to do is to insert records specifying "Long Distance" as the associated record type. So what I do is to first retrieve the correct Id for the "Long Distance" record type querying the RecordType object, which works perfectly (I get a "abc30935945849xxx" kind of string). And then I attempt to set this value for the RecordTypeId field of the Service object I created ago using sfapi.CreateObject("Service__c") but to no avail: run-time error Invalid Field Index::RecordTypeId. Note: I have been able to upload many records from an excel sheet WITHOUT trying to specify the RecordTypeId value, so there is nothing wrong with the connection, creating the object, or inserting...

I also tried with RecordTypeId__c, RecordType, recordtypeid etc... but the field simply isn't there. Every other field of the object is, only this not. Watching the Service object variable lets me actually browse through its fields and no record type field is there.

How can I make CreateObject include("Service__c") the RecordTypeId field in the object so that I can modify it?

Does the SForce Office Toolkit 3.0 API (6.0) support modification of the RecordTypeId standard field in Custom Objects?

The Office Toolkit uses the 6.0 endpoint by default.  Change the endpoint to the 7.0 endpoint using the SetServerURL call of the Session object.
Wouldn't hurt to get the latest version of the Toolkit either.  Earlier versions had trouble with 7.0 endpoints, latest version is solid (Thanks to Foghorn!).
DBAmp Developer
Thanks guys!
Downloaded latest office toolkit 3.00.0041 (I was using 3.00.0031). Then specified sfApi.SetServerUrl and everything is running smooth now!