Today, Salesforce moved the mobile framework to GA. We’ve been using this in RingDNA since it’s first beta release at Dreamforce.
A common issue w/ large native applications (connected to a remote datasource) is the amount of UI bindings you need to code.
Objective-c doesn’t like null values all that much… If you’re building a lot of simple read-only screens, it’ll take quite a bit of code to check for null values on every field. You can use obj-c blocks in your response callback to insert empty NSString objects in place of nulls to allow for auto-binding to UI elements.
So, using blocks we can do something like:
- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse {
NSDictionary *dict = (NSDictionary *)jsonResponse;
NSLog(@"Response: %@", dict);
if ([[dict valueForKey:@"totalSize"] intValue] > 0) {
NSDictionary *firstResult = [[dict valueForKey:@"records"] objectAtIndex:0];
[firstResult enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSLog(@"KEY: %@", key);
if ([key isEqualToString:@"Account"]) {
[obj enumerateKeysAndObjectsUsingBlock:^(id accountKey, id accountObj, BOOL *accountStop) {
if ((NSNull *)accountObj == [NSNull null]) {
NSLog(@"NULL Found: %@", accountKey);
}
}];
}
}];
self.contactSFDC = firstResult;
[self setContactInfo:firstResult];
} else {
// Load alternate view? No contact was found
}
}
You can see that this is less code than looping over the allKeys NSArray (it has performance benefits as well). I’m showing the nested Account relation in this response so you can see how to traverse two levels from the SOQL query. Also, notice the casting of the obj to NSNull so we can properly check if the field is null.
