async Task <Tuple <List <dynamic>, string> > QueryRecordsPaged(string query, bool queryAll = false) { List <dynamic> recordList = new List <dynamic>(); Salesforce.Common.Models.Json.QueryResult <dynamic> queryRecordResult = queryAll ? await Client.QueryAllAsync <dynamic>(query) : await Client.QueryAsync <dynamic>(query); recordList.AddRange(queryRecordResult.Records); return(new Tuple <List <dynamic>, string>(recordList, queryRecordResult.NextRecordsUrl)); }
public IActionResult SFExamplePost() { var auth = new AuthenticationClient(); auth.UsernamePasswordAsync(_configuration.GetValue <string>("SFConsumerKey"), _configuration.GetValue <string>("SFConsumerSecret"), _configuration.GetValue <string>("SFUserName"), _configuration.GetValue <string>("SFPassword")).Wait(); var instanceUrl = auth.InstanceUrl; var accessToken = auth.AccessToken; var apiVersion = auth.ApiVersion; var client = new ForceClient(instanceUrl, accessToken, apiVersion); string virtualMachineName = string.Empty; string status = string.Empty; string envRecordId = string.Empty; string accReqRecordId = string.Empty; if (!string.IsNullOrEmpty(Request.Form["btnRequestVM"])) { virtualMachineName = Request.Form["txtVirtualMachineName"]; status = "Processing"; // Add an environment Environment environment = new Environment() { UserName__c = User.Identity.Name, VirtualMachineName__c = virtualMachineName, Status__c = status }; var success = client.CreateAsync("Environment__c", environment).Result; if (success.Success) { envRecordId = success.Id; } else { // Handle error here } } else if (!string.IsNullOrEmpty(Request.Form["btnCheckStatus"])) { envRecordId = Request.Form["hidEnvRecordId"]; virtualMachineName = Request.Form["hidVirtualMachineName"]; status = "Processing"; // Check the environment status var environments = client.QueryAsync <Environment>(string.Format("SELECT id, UserName__c, VirtualMachineName__c, Status__c FROM Environment__c WHERE id = '{0}'", envRecordId)).Result; if (environments.Records.Count > 0) { if (environments.Records[0].Status__c == "Ready") { status = "Ready"; } } } else if (!string.IsNullOrEmpty(Request.Form["btnRequestAccess"])) { virtualMachineName = Request.Form["hidVirtualMachineName"]; status = "Requested"; AccessRequest accessRequest = new AccessRequest() { UserName__c = User.Identity.Name, VirtualMachineName__c = virtualMachineName, IPAddress__c = Request.HttpContext.Connection.RemoteIpAddress.ToString(), Status__c = status }; var success = client.CreateAsync("AccessRequest__c", accessRequest).Result; if (success.Success) { accReqRecordId = success.Id; } else { // Handle error here } } else if (!string.IsNullOrEmpty(Request.Form["btnCheckAccess"])) { accReqRecordId = Request.Form["hidAccReqRecordId"]; virtualMachineName = Request.Form["hidVirtualMachineName"]; status = "Requested"; // Check the access request status var accessRequests = client.QueryAllAsync <AccessRequest>(string.Format("SELECT id, UserName__c, VirtualMachineName__c, IPAddress__c, Status__c FROM AccessRequest__c WHERE id = '{0}'", accReqRecordId)).Result; if (accessRequests.Records.Count > 0) { if (accessRequests.Records[0].Status__c == "Granted") { status = "Granted"; } } } ViewBag.VirtualMachineName = virtualMachineName; ViewBag.Status = status; ViewBag.User = User.Identity.Name; ViewBag.IPAddress = Request.HttpContext.Connection.RemoteIpAddress; ViewBag.EnvRecordId = envRecordId; ViewBag.AccReqRecordId = accReqRecordId; return(View()); }
public async Task QueryAll_Accounts_IsNotEmpty() { var accounts = await _client.QueryAllAsync <Account>("SELECT Id, name, description FROM Account"); Assert.IsNotNull(accounts); }