1: public void QuerySalesforce(){ 2: // build LEAD query
3: XDocument xDoc = XDocument.Load(@"SalesForceSchema.xml");
4: var fields = from x in xDoc.Root.Element("Lead").Elements("Field") 5: select x.Attribute("SfName").Value; 6: string query = String.Format("SELECT {0} FROM Lead 7: WHERE Email = 'something@email.com'"
8: , string.Join(",", fields)); 9:
10: string sfQuery = String.Format("{0}/services/data/v23.0/query?q={1}", 11: token.instance_url,
12: query);
13: HttpWebRequest request = HttpWebRequest.Create(sfQuery) as HttpWebRequest;
14: request.Headers.Add("Authorization", "OAuth " + token.access_token); 15: request.ContentType = "application/json";
16: request.Method = "GET";
17:
18: WebResponse webResponse = request.GetResponse();
19: var sr = new System.IO.StreamReader(webResponse.GetResponseStream());
20: string json = sr.ReadToEnd();
21: var leads = js.Deserialize<sfdcLeadCollection<sfdcLeadForCollection>>
22: (HttpUtility.UrlDecode(json));
23: }
24:
25: public class sfdcLeadCollection<T> { 26: public bool Done { get; set; } 27: public int TotalSize { get; set; } 28: public string nextRecordsUrl { get; set; } 29: public List<T> Records { get; set; } 30: }
31:
32: public class sfdcAttributes { 33: public string Type { get; set; } 34: public string Url { get; set; } 35: }
36:
37: public class sfdcLeadForCollection : sObjectLead { 38: public sfdcAttributes Attributes { get; set; } 39: }
40:
41: public class sObjectLead { 42: public string Id { get; set; } 43: public string Email { get; set; } 44: public string FirstName { get; set; } 45: public string LastName { get; set; } 46: public string Company { get; set; } 47: public string Phone { get; set; } 48: public string MobilePhone { get; set; } 49: public string Fax { get; set; } 50: public string Website { get; set; } 51: public string Street { get; set; } 52: public string City { get; set; } 53: public string State { get; set; } 54: public string Country { get; set; } 55: public string PostalCode { get; set; } 56: }