Salesforce Mobile:
Retrieve the list of objects from salesforce in iOS native mobile app
Description: Using the salesforce mobile iOS-native SDK we can retrieve the list of objects using “requestForDescribeGlobal” SDK method. This method will return the data of all the objects from your salesforce org.
Code:
In your viewDidLoad method make a request to salesforce
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"App Title";
SFRestRequest* request = [[SFRestAPI sharedInstance] requestForDescribeGlobal];
NSLog(@"request:didLoadResponse: #request: %@", request);
[[SFRestAPI sharedInstance] send:request delegate:self];
}
To get the result response you can use didLoadResponse Method as:
- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse {
NSArray *records = [jsonResponse objectForKey:@"sobjects"];
NSLog(@"request:didLoadResponse: #records: %lu", (unsigned long)records.count);
self.dataRows = records;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
Now if you check your console log this will return the no of records found in salesforce i.e number of objects in your salesforce org.
To Populate these records in a list view you can add code as:
- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView_ dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
// Configure the cell to show the data.
NSDictionary *obj = [dataRows objectAtIndex:indexPath.row];
NSString *fileId = obj[@"id"];
NSInteger tag = [fileId hash];
cell.textLabel.text = obj[@"name"];
cell.detailTextLabel.text = obj[@"label"];
}];
return cell;
}
This will populate the list with all the objects of your salesforce org with name and label.
Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Salesforce customization, App development or any other software development assistance please contact us at salesforce@webners.com
