Skip to content

Instantly share code, notes, and snippets.

@welbesw
Created June 7, 2016 18:10
Show Gist options
  • Save welbesw/59bcd3379f8b6d2b124f01e12109a638 to your computer and use it in GitHub Desktop.
Save welbesw/59bcd3379f8b6d2b124f01e12109a638 to your computer and use it in GitHub Desktop.
func fetchContacts(completion completion: (contacts: [SalesforceContact], error: NSError?) -> ()) {
//TODO: Confirm that user is authenticated
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Id, FirstName, LastName, Email FROM Contact")
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: { (error) in
//Handle the error
print("sendRESTRequest error: \(error.localizedDescription)")
}) { (response) in
//Parse the response
print("sendRESTRequest response")
guard let records = response["records"] as? [[String : AnyObject]] else {
let error = NSError(domain: self.errorDomain, code: -100, userInfo: nil)
completion(contacts: [], error: error)
return
}
let contacts = records.map{ SalesforceContact(dictionary: $0) }
completion(contacts: contacts, error: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment