/// <summary> /// Inserts a StatusCall Object to SF. /// </summary> /// <param name="client">The authenticated ForceClient Implementation of IForceClient </param> /// <param name="spon">The Spotzer Purchase Order Number</param> /// <param name="approvalUrl">Web Approval URL</param> /// <param name="status">Status</param> /// <param name="orderId">Salesforce Order.Id</param> /// <param name="taskId">Salesforce Task.Id</param> /// <param name="freelancerId">Salesforce Freelancer.Id</param> /// <param name="isTest">If true - transaction will be rolled back after completion</param> /// <param name="encryptedRole">Salesforce role identifier</param> /// <returns>String version of Id of Record to be inserted.</returns> private static async Task <String> InsertStatusCallToSF(IForceClient client, string spon, string approvalUrl, int?status, string orderId, string taskId, string freelancerId, bool?isTest, string encryptedRole) { //Create a custom Record Log.Instance.Info(String.Format("Inserting Statuscall_Log__c (Spon={0},approvalUrl={1},status={2},orderId={3},taskId={4},freelancerId={5},isTest={6},encryptedRole={7})", spon, approvalUrl, status, orderId, taskId, freelancerId, isTest, encryptedRole)); //Tidy up - this can be created else where and this function made more generic. dynamic statusUpdate = new ExpandoObject(); statusUpdate.SPON__c = spon; statusUpdate.encryptedRole__c = encryptedRole; statusUpdate.freelancerId__c = freelancerId; statusUpdate.isTest__c = isTest; statusUpdate.orderId__c = orderId; statusUpdate.Status__c = status; statusUpdate.taskId__c = taskId; statusUpdate.ApprovalURL__c = approvalUrl; statusUpdate.ProcessOnInsert__c = true; string recordId = await client.CreateAsync("Statuscall_Log__c", statusUpdate); if (String.IsNullOrEmpty(recordId)) { Log.Instance.Info("Failed to create custom test record."); return(null); } Log.Instance.Info("StatusCall ID:" + recordId); return(recordId); }
/// <summary> /// Runs the business logic here. /// </summary> public async Task Run() { this.log.Info("BusinessProcess ID : " + SalesforceManager.GetHashCode()); this.log.Info("This has been run"); ForceClient = await this.SalesforceManager.LoginAndGetForceApi(); var lstUsers = await QueryUserFromSalesforce(ForceClient); string csv = ""; //using (var memoryStream = new MemoryStream()) //using (var streamWriter = new StreamWriter(memoryStream)) //using (var streamReader = new StreamReader(memoryStream)) //using (var writer = new CsvWriter(streamWriter)) //{ // writer.Configuration.BufferSize = 2048; // writer.Configuration.QuoteAllFields = true; // writer.WriteHeader<UserPoCo>(); // foreach (var record in lstUsers) // { // writer.WriteRecord(record); // } // memoryStream.Position = 0; // memoryStream.Flush(); // csv = streamReader.ReadToEnd(); //} }
public async Task<List<UserPoCo>> QueryUserFromSalesforce(IForceClient client) { var lstUsers = new List<UserPoCo>(); var nextUrl = await GetUser(client, lstUsers); await GetNextUser(client, nextUrl, lstUsers); return lstUsers; }
public async Task<String> GetUser(IForceClient client, List<UserPoCo> lstUsers) { string restQuery = "select Id , Employee_ID__c , Email , Alias , Zone__c , Zone_Code__c , Region__c , Region_Code__c , IsActive from User where IsActive = true and Employee_ID__c != null "; var results = await client.QueryAsync<UserPoCo>(restQuery); lstUsers.AddRange(results.Records); return results.NextRecordsUrl; }
public async Task CreateLotsOfAccounts(IForceClient forceClient) { var account = new Account { Name = "Test Account", Description = "New Account Description" }; for (var i = 0; i < 1000; i++) { account.Name = "Test Account (" + i + ")"; await forceClient.CreateAsync("Account", account); } }
private static async Task <String> InsertObjectToSF(IForceClient client, ExpandoObject objectToInsert, String objectName) { String returnId = await client.CreateAsync(objectName, objectToInsert); if (String.IsNullOrEmpty(returnId)) { Log.Instance.Info(String.Format("Failed to create {0} record.", objectName)); return(null); } Log.Instance.Info(String.Format("{0} ID: {1}", objectName, returnId)); return(returnId); }
public async Task GetNextUser(IForceClient client, string nextRecordsUrl, List<UserPoCo> lstUsers) { if (!string.IsNullOrEmpty(nextRecordsUrl)) { while (true) { var continuationResults = await client.QueryContinuationAsync<UserPoCo>(nextRecordsUrl); lstUsers.AddRange(continuationResults.Records); if (string.IsNullOrEmpty(continuationResults.NextRecordsUrl)) break; nextRecordsUrl = continuationResults.NextRecordsUrl; } } }
/// <summary> /// Initialize the form while loading /// </summary> private async void InitializeForm() { this.btnSyncWithJiraAndSF.Enabled = false; this.btnSendSummaryReport.Enabled = false; Task <IForceClient> createAuthenticationClient = SalesforceProxy.CreateAuthenticationClient(); IForceClient client = await createAuthenticationClient; if (client != null) { this.btnSyncWithJiraAndSF.Enabled = true; this.btnSendSummaryReport.Enabled = true; } }
public static async Task<IForceClient> CreateAuthenticationClient() { var auth = new AuthenticationClient(); // Authenticate with Salesforce var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase) ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token"; await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url); Client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); return Client; }
public static async Task <IForceClient> CreateAuthenticationClient() { var auth = new AuthenticationClient(); // Authenticate with Salesforce var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase) ? "https://test.salesforce.com/services/oauth2/token" : "https://login.salesforce.com/services/oauth2/token"; await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url); AccessToken = auth.AccessToken; Client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); return(Client); }
public SalesForceClient(AuthModel auth) { var authenticator = new AuthenticationClient(); authenticator.UsernamePasswordAsync( auth.ConsumerKey , auth.ConsumerSecret , auth.Username , String.Concat(auth.Password, auth.SecurityToken) , auth.TokenRequestPointUrl).Wait(); var instanceUrl = authenticator.InstanceUrl; var accessToken = authenticator.AccessToken; var apiVersion = authenticator.ApiVersion; _client = new ForceClient(instanceUrl, accessToken, apiVersion, new HttpClient()); }
private void initialize_helper() { var securityToken = ""; var consumerKey = ""; var consumerSecret = ""; var username = ""; var password = "";//password + securityToken; var auth = new AuthenticationClient(); var url = "https://login.salesforce.com/services/oauth2/token"; auth.UsernamePasswordAsync(consumerKey, consumerSecret, username, password, url).Wait(); inner_sf_client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion); inner_http_client = new HttpClient(); inner_http_client.DefaultRequestHeaders.Add("Authorization", "Bearer " + auth.AccessToken); }
public void Init() { if (string.IsNullOrEmpty(_consumerKey) && string.IsNullOrEmpty(_consumerSecret) && string.IsNullOrEmpty(_username) && string.IsNullOrEmpty(_password) && string.IsNullOrEmpty(_organizationId)) { _consumerKey = Environment.GetEnvironmentVariable("ConsumerKey"); _consumerSecret = Environment.GetEnvironmentVariable("ConsumerSecret"); _username = Environment.GetEnvironmentVariable("Username"); _password = Environment.GetEnvironmentVariable("Password"); _organizationId = Environment.GetEnvironmentVariable("OrganizationId"); } // Use TLS 1.2 (instead of defaulting to 1.0) const int SecurityProtocolTypeTls11 = 768; const int SecurityProtocolTypeTls12 = 3072; ServicePointManager.SecurityProtocol |= (SecurityProtocolType)(SecurityProtocolTypeTls12 | SecurityProtocolTypeTls11); _auth = new AuthenticationClient(); _auth.UsernamePasswordAsync(_consumerKey, _consumerSecret, _username, _password).Wait(); _client = new ForceClient(_auth.InstanceUrl, _auth.AccessToken, _auth.ApiVersion); }
public SalesForceQuery(IForceClient forceClient, IMapper mapper) { _forceClient = forceClient; _mapper = mapper; }
public SalesforceLayerTest() { _forceClient = ForceClientFactory.CreateAsync(ClientId, ClientSecret, Username, Password, IsProduction) .GetAwaiter().GetResult(); }
public CommandService(IForceClient forceClient) { _forceClient = forceClient; }
/// <summary> /// Initialize the form while loading /// </summary> private async void InitializeForm() { this.btnLookUpInJiraAndSF.Enabled = false; this.btnSyncCaseInJiraAndSF.Enabled = false; this.Text = "Smart Worker - [email protected]"; Task <IForceClient> createAuthenticationClient = SalesforceProxy.CreateAuthenticationClient(); IForceClient client = await createAuthenticationClient; if (client != null) { this.btnLookUpInJiraAndSF.Enabled = true; this.btnSyncCaseInJiraAndSF.Enabled = true; } this.ddlReviewerEmailAddress.Items.Clear(); List <string> reviewerEmailAddressList = new List <string>(); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); reviewerEmailAddressList.Add("*****@*****.**"); this.ddlReviewerEmailAddress.DataSource = reviewerEmailAddressList; }
public QueryService(IForceClient forceClient) { _forceClient = forceClient; }