+ Start a Discussion
Jim BoudreauxJim Boudreaux 

request didLoadResponse question

I started a new project using the Native Force.com REST App template that comes with the Mobile SDK. I am building a very simple nested tableview app similar to how the Salesforce Mobile App works, you start with a tableview showing a list of Totalreport__c records, tapping one navigates you to a tableview of related Inspection__c records, tapping one navigates you to a tableview of related Result__c records, tapping one navigates you to a detail page for that record. 
Here is the tricky part. I want to display a picker view on the Result__c detail page, the contents of which are build from Device_Type__c records. Mind you, records, not the values of a picklist on a custom object, actual records. The picker view should use the Name field as the label and the Id field as the value and the selected option should be stored in a lookup field in the Result__c record. (Basically I want to present the user with a picker view interface for a lookup field on a custom object)
What I am doing right now isn't working. In the ResultTableViewController.m viewDidLoad method I am using a SFRestRequest to query the server to return the chosen Inspection__c record's related Result__c records and in the same method I am also using an SFRestRequest to query the Device_Type__c records. (I am doing it here because I need the value of a field in the chosen Inspection__c record to use in the Where clause of the Device_Type__c query.)
The problem lies in the fact that even though I have two different SFRestRequests, there is only one request didLoadResponse method that handles both, and therefore I only get back one jsonResponse, either with the Result__c records, or the Device_Type__c records.

How do I split them up and handle them separately?



- (void)viewDidLoad
    [super viewDidLoad];
    self.title = inspectionName;
    //Result__c query being concatenated to include the Inspection__c Id
    NSString *resultSelect =@"SELECT ID, Name, Mobile_1__c, Number__c, Type__c, Location__c, System_Type_Id__c, Floor_Name__c FROM Result__c WHERE Device_Class__c != 'Subcomponent' AND Inspection__c = '";
    NSString *resultQuery = [resultSelect stringByAppendingString:[inspectionId stringByAppendingString:@"' ORDER BY Floor_Order__c"]];

    //Result__c query sent
    SFRestRequest *resultRequest = [[SFRestAPI sharedInstance] requestForQuery: resultQuery];
    [[SFRestAPI sharedInstance] send:resultRequest delegate:self];

    //Device_Type__c query being concatenated to include the System_Type_Id__c Id
    NSString *deviceTypeSelect =@"SELECT Id, Name FROM Device_Type__c WHERE Class__c != 'Subcomponent' AND System_Type__c = '";
    NSString *deviceTypeQuery = [deviceTypeSelect stringByAppendingString:[inspectionSystemTypeId stringByAppendingString:@"' Order by Name"]];
    //Device_Type__c query sent
    SFRestRequest *deviceTypeRequest = [[SFRestAPI sharedInstance] requestForQuery: deviceTypeQuery];
    [[SFRestAPI sharedInstance] send:deviceTypeRequest delegate:self];

#pragma mark - SFRestAPIDelegate
- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse {
    NSArray *records = [jsonResponse objectForKey:@"records"];
    NSLog(@"request:didLoadResponse:# of records: %d", records.count);
    //Results to display in the ResultTableView
    self.dataRows = records;
    //Trying to figure out a way to put the response records of the Device_Type__c query into the deviceType NSArray. This obviously doesn't work and is where I need help
    deviceTypes = records;
    [self.tableView reloadData];




This is an ideal use case for the block-based REST methods I contributed to the native iOS SDK. :)