private static async Task RunTest() { AuthInfo authInfo = GetAuthInfo(); AuthenticationClient auth = new AuthenticationClient(authInfo.ApiVersion); try { await auth.UsernamePasswordAsync(authInfo.ClientId, authInfo.ClientSecret, authInfo.Username, authInfo.Password, authInfo.TokenRequestEndpoint); Console.WriteLine("Successfully connected to Salesforce"); } catch (ForceAuthException ex) { Console.WriteLine("ForceAuthException: " + ex.Message); return; } catch (Exception ex) { Console.WriteLine("General Exception at login: "******"SELECT Id, Name, SystemModstamp, Account.Id, Account.Name, Account.SystemModstamp FROM Contact", false); List <CustomAccount> customAccounts = await client.Query <CustomAccount>("SELECT Id, CustomerPriority__c FROM Account", false); //Using a dynamic object dynamic dynoObject = new ExpandoObject(); dynoObject.Name = "Test Account"; dynoObject.Description = "Test Account description"; CreateResponse resp = await client.CreateRecord <dynamic>("Account", dynoObject); } catch (ForceApiException ex) { Console.WriteLine("ForceApiException: " + ex.Message); return; } catch (Exception ex) { Console.WriteLine("General Exception: " + ex.Message); return; } return; }
async private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(AccessToken)) { OrganizationsList.Visibility = Visibility.Collapsed; AuthBrowser.Visibility = Visibility.Visible; var url = Common.FormatAuthUrl( AuthorizationEndpointUrl, ResponseTypes.Code, ConsumerKey, CallbackUrl, DisplayTypes.Touch); AuthBrowser.Navigate(new Uri(url)); return; } var auth = new AuthenticationClient(); await auth.WebServer(ConsumerKey, ConsumerSecret, CallbackUrl, AccessToken); var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); var accounts = await client.Query<Account>("SELECT id, name, description FROM Account"); OrganizationsList.Visibility = Visibility.Visible; AuthBrowser.Visibility = Visibility.Collapsed; OrganizationsList.ItemsSource = accounts; }
public async Task<string> Get([FromUri] string instanceUrl, [FromUri] string accessToken, [FromUri] string apiVersion, [FromUri] string query) { var client = new ForceClient(instanceUrl, accessToken, apiVersion); var queryResults = await client.Query<object>(query); var response = JsonConvert.SerializeObject(queryResults); return response; }
public async Task QueryNoResults() { ForceClient client = await forceClientFixture.GetForceClient(); List <SfCase> cases = await client.Query <SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case WHERE CaseNumber = '999999'"); Assert.False(cases == null); Assert.True(cases.Count == 0); }
public async Task QueryRelationship() { //This isn't fully supported yet - this wont query all if there are NextRecordsUrl values in the subqueries ForceClient client = await forceClientFixture.GetForceClient(); List <AccountWithContactsSub> accounts = await client.Query <AccountWithContactsSub>("SELECT Account.Name, (Select Contact.Name from Contacts) FROM Account"); Assert.NotNull(accounts); Assert.True(accounts[0].Contacts.Done); Assert.NotNull(accounts[0].Contacts.Records[0].Name); }
public async Task Query() { ForceClient client = await forceClientFixture.GetForceClient(); List <SfCase> cases = await client.Query <SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case"); SfCase firstCase = cases[0]; Assert.False(cases == null); Assert.True(cases.Count > 1); Assert.NotNull(firstCase.CaseNumber); }
public async void QueryNoResults() { ForceClient client = CreateMockClient( "https://na15.salesforce.com", "v41.0", "https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id%20FROM%20Case", "query_empty_result.json", HttpStatusCode.OK); List <SfCase> cases = await client.Query <SfCase>("SELECT Id FROM Case"); Assert.NotNull(cases); Assert.Empty(cases); }
public async Task Load() { var auth = new AuthenticationClient(); // //TODO: Move token information to Lambda Environment variables. // // //Pass in the login information await auth.UsernamePasswordAsync("3MVG9LBJLApeX_PBn4SXK4vWIZgUwaByh5aAkEKtY_N8.E7cwD1.bEKSetVd5EjOnuie6kB1gmDridf8KPpSz", "439C541B6523A7F8C5F8BD6CCFEFC6F184C0FEE89FF2D3C95F58156A3C060923", "*****@*****.**", "Gl1d3w3ll!2019", "https://login.salesforce.com/services/oauth2/token"); //the AuthenticationClient object will then contain the instance URL and access token to be used in each of the API calls ForceClient client = new ForceClient(auth.AccessInfo.InstanceUrl, auth.ApiVersion, auth.AccessInfo.AccessToken); Pricebooks = client.Query <SfPricebook2>("SELECT Id, Name FROM Pricebook2").Result; Products = client.Query <SfProduct2>("SELECT Id, Name FROM Product2").Result; PriceBookEntries = client.Query <SfPricebookEntry>("SELECT Id, Name, Product2Id, Pricebook2Id, UnitPrice FROM PricebookEntry").Result; Accounts = client.Query <SfAccount>("SELECT Id, Name FROM Account").Result; AccessToken = auth.AccessInfo.AccessToken; }
public async void Requests_CheckHttpRequestMessage_UserAgent() { var httpClient = new HttpClient(new ServiceClientRouteHandler(r => Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-libraries-dotnet/v29"))); var forceClient = new ForceClient("http://localhost:1899", "accessToken", "v29", httpClient); try { // suppress error; we only care about checking the header var query = await forceClient.Query<object>("query"); } catch (Exception) { } }
public async void QueryNestedObjects() { ForceClient client = CreateMockClient( "https://na15.salesforce.com", "v41.0", "https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp%20FROM%20Case", "query_case_result.json", HttpStatusCode.OK); List <SfCase> cases = await client.Query <SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case"); SfCase firstCase = cases[0]; Assert.False(cases == null); Assert.Equal("00001000", cases[0].CaseNumber); Assert.Equal("Edge Communications", cases[0].Account.Name); Assert.Equal("Rose Gonzalez", cases[0].Contact.Name); Assert.Equal(26, cases.Count); }
public async Task <dynamic> ExecuteSourceOperation(string intermediateJson) { ForceClient client = new ForceClient(await GetClientOptions()); dynamic result; try { result = await client.Query <dynamic>(intermediateJson, false); await LogInfo("Salesforce Query Succesfully Executed"); } catch (Exception ex) { await LogError("Salesforce Query Execution Failed", ex.Message); throw; } return(result); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "salesforce/objects/query")] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject <QueryRequest>(requestBody); ForceClient client = new ForceClient(data); try { //var result = await client.GetObjectBasicInfo(data.ObjectTypeName); var result = await client.Query <dynamic>(data.QueryString, data.QueryAll = false); // RemoveAttribute.Strip(result); return((ActionResult) new OkObjectResult(result)); } catch (System.Exception ex) { throw; } }
public async void QueryNestedObjects() { var mockHandler = new MockHttpClientHandler(); HttpResponseMessage respMsg = MockResponse.GetResponse("query_case_result.json", HttpStatusCode.OK); Uri requestUri = new Uri(@"https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp%20FROM%20Case"); mockHandler.AddMockResponse(requestUri, respMsg); HttpClient httpClient = new HttpClient(mockHandler); ForceClient client = new ForceClient("https://na15.salesforce.com", "v41.0", "dummyToken", httpClient); List <SfCase> cases = await client.Query <SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case"); SfCase firstCase = cases[0]; Assert.False(cases == null); Assert.Equal("00001000", cases[0].CaseNumber); Assert.Equal("Edge Communications", cases[0].Account.Name); Assert.Equal("Rose Gonzalez", cases[0].Contact.Name); Assert.Equal(26, cases.Count); }
private static async Task RunTest() { AuthInfo authInfo = GetAuthInfo(); AuthenticationClient auth = new AuthenticationClient(authInfo.ApiVersion); try { await auth.UsernamePasswordAsync(authInfo.ClientId, authInfo.ClientSecret, authInfo.Username, authInfo.Password, authInfo.TokenRequestEndpoint); Console.WriteLine("Successfully connected to Salesforce"); } catch (ForceAuthException ex) { Console.WriteLine("ForceAuthException: " + ex.Message); return; } catch (Exception ex) { Console.WriteLine("General Exception at login: "******"SELECT Id, Name, SystemModstamp, Account.Id, Account.Name, Account.SystemModstamp FROM Contact", false); List <CustomAccount> customAccounts = await client.Query <CustomAccount>("SELECT Id, CustomerPriority__c FROM Account", false); //Using a dynamic object dynamic dynoObject = new ExpandoObject(); dynoObject.Name = "Test Account"; dynoObject.Description = "Test Account description"; CreateResponse resp = await client.CreateRecord <dynamic>("Account", dynoObject); // Asynchronous large result sets and batching: // Query<T> method will retrieve the full result set before returning. // In cases where you are working with large result sets, you may want to retrieve the batches asynchronously for better performance. // First create the async enumerable. At this point, no query has been executed. // batchSize can be omitted to use the default (usually 2000), or given a custom value between 200 and 2000. IAsyncEnumerable <SfContact> contactsEnumerable = client.QueryAsync <SfContact>("SELECT Id, Name FROM Contact ", batchSize: 200); // Get the enumerator, in a using block for proper disposal using (IAsyncEnumerator <SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator()) { // MoveNext() will execute the query and get the first batch of results. // Once the inital result batch has been exhausted, the remaining batches, if any, will be retrieved. while (await contactsEnumerator.MoveNext()) { SfContact contact = contactsEnumerator.Current; // process your results } } } catch (ForceApiException ex) { Console.WriteLine("ForceApiException: " + ex.Message); return; } catch (Exception ex) { Console.WriteLine("General Exception: " + ex.Message); return; } return; }
private static async Task RunSample() { var auth = new AuthenticationClient(); // Authenticate with Salesforce Console.WriteLine("Authenticating with Salesforce"); await auth.UsernamePassword(ConsumerKey, ConsumerSecret, Username, Password); Console.WriteLine("Connected to Salesforce"); var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); // Create a sample record Console.WriteLine("Creating test record."); var account = new Account { Name = "Test Account" }; account.Id = await client.Create(Account.SObjectTypeName, account); if (account.Id == null) { Console.WriteLine("Failed to create test record."); return; } Console.WriteLine("Successfully created test record."); // Update the sample record // Shows that annonymous types can be used as well Console.WriteLine("Updating test record."); var success = await client.Update(Account.SObjectTypeName, account.Id, new { Name = "Test Update" }); if (!success) { Console.WriteLine("Failed to update test record!"); return; } Console.WriteLine("Successfully updated the record."); // Retrieve the sample record // How to retrieve a single record if the id is known Console.WriteLine("Retrieving the record by ID."); account = await client.QueryById<Account>(Account.SObjectTypeName, account.Id); if (account == null) { Console.WriteLine("Failed to retrieve the record by ID!"); return; } Console.WriteLine("Retrieved the record by ID."); // Query for record by name Console.WriteLine("Querying the record by name."); var accounts = await client.Query<Account>("SELECT ID, Name FROM Account WHERE Name = '" + account.Name + "'"); account = accounts.FirstOrDefault(); if (account == null) { Console.WriteLine("Failed to retrieve account by query!"); return; } Console.WriteLine("Retrieved the record by name."); // Delete account Console.WriteLine("Deleting the record by ID."); success = await client.Delete(Account.SObjectTypeName, account.Id); if (!success) { Console.WriteLine("Failed to delete the record by ID!"); return; } Console.WriteLine("Deleted the record by ID."); }