Using Record Types

It’s common practice to have Record Types within our Salesforce orgs. These can obviously be very useful, but they also throw up some issues for app developers, as the associated Record Type IDs  are not consistent across Developer Orgs, Sanboxes and Production instances.

MobileCaddy overcomes this issue by mobilising the Record Type Name along with the Record Type Id, and allows the developer to interchangeably use these in insert and update calls to the local DB, as well as making these available in the results of any database read requests.

If we take for example our Account & Contacts tutorial, and add a Record Type to our Contact object and then see how this can be accessed and used in code. I have created 2 Record Types, “Developer” and “Administrator”.

Reading with Record Types

Within our code it’s likely that we’ll want to do some conditional logic, or presentation, based upon Record Types. And this is possible with MobileCaddy as each read call returns records enriched with the Record Type Name associated with the Record Type ID for each record.

In the screenshot you can see that my returned Contact object contains 2 fields for Record Types – RecordTypeId and RecordTypeName – and that my Contact Rose Gonzalez has been assigned a Developer record type.

Use of MobileCaddy to access Salesforce Record Types by name

At present it is not possible to use RecordTypeName within the WHERE clause of smartSql calls. You can however list all RecordType values for a table to find the associated RecordTypeId and use that within smartSql calls.

For example;

Writing with Record Types

As with the read calls it is possible to use Record Type Names when inserting and updating records into the local DB too. If the supplied RecordTypeName is identified then the MobileCaddy libraries will automatically insert the relevant RecordTypeId field also, though it is possible to include the RecordTypeId field in the insertRecord and updateRecord calls also or instead of the RecordTypeName.

With the above in mind you can see that as a developer of MobileCaddy applications you don’t need to concern yourself with RecordTypeIds.