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.
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;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
// Get our known record types for the Contact__ap table devUtils.getRecordTypes("Contact__ap").then(function(r){console.log(JSON.stringify(r));}); // The response {"01224000000LRihAAG":"Developer","01224000000LRimAAG":"Administrator"} // Our SmartSQL call for only Developer records, using the RecordTypeId devUtils.smartSql( "SELECT * FROM {Contact__ap} WHERE {Contact__ap:RecordTypeId} = '01224000000LRihAAG'") .then(function(r){console.log(JSON.stringify(r.records[0]));}); // The response { "RecordTypeId": "01224000000LRihAAG", "Title": "SVP, Procurement", "SystemModstamp": "2017-02-22T10:04:19.000Z", "OwnerId": "00524000000EnWoAAK", "MobilePhone": "(512) 757-9340", "MC_Proxy_ID__c": "", "LastName": "Gonzalez", "LastModifiedDate": "2017-02-22T10:04:19.000Z", "LastModifiedById": "00524000000EnWoAAK", "Name": "Rose Gonzalez", "FirstName": "Rose", "Email": "rose2@edge.com", "IsDeleted": false, "CreatedDate": "2015-01-06T10:39:16.000Z", "CreatedById": "00524000000EnWoAAK", "Id": "00324000001qr2IAAQ", "AccountId": "00124000003Q4MCAA0", "_soupEntryId": 1, "_soupLastModifiedDate": 1487757814863, "RecordTypeName": "Friend" } |
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.