public bool IntegerateSfCustServiceLine(string userName, string password) { logger.Info("Scheduled Customer Service Line job triggered"); DBAction dba = new DBAction(_integrationAppSettings); string filterstring = dba.GetSalesforceInformation().Replace("\n", ""); bool result = false; List <CustomerServiceLine> ltsCusline = new List <CustomerServiceLine>(); SoapClient ss = new SoapClient(); LoginResult lr = new LoginResult(); LoginScopeHeader LH = new LoginScopeHeader(); if (sessionId == null | sessionId == "") { lr = ss.login(null, userName, password); if (!lr.passwordExpired) { sessionId = lr.sessionId.ToString().Trim(); serverUrl = lr.serverUrl.ToString().Trim(); } } // Store SessionId in SessionHeader; We will need while making query() call SessionHeader sHeader = new SessionHeader(); sHeader.sessionId = sessionId; // Variable to store query results QueryResult qr = new QueryResult(); SoapClient ss1 = new SoapClient(); ss1.ChannelFactory.Endpoint.Address = new System.ServiceModel.EndpointAddress(serverUrl); var lastintegratedDate = dba.GetLastintegratedDateandTime("Last_CustomerLineIntegrate"); // if (lastintegratedDate == null) ss1.query(sHeader, null, null, null, @"SELECT Id ,Name ,enrtcr__Remaining__c ,enrtcr__Item_Overclaim__c ,enrtcr__Support_Contract__c ,enrtcr__Support_Contract__r.Name ,enrtcr__Support_Contract__r.enrtcr__End_Date__c ,enrtcr__Support_Contract__r.enrtcr__Status__c ,enrtcr__Support_Contract__r.enrtcr__Funding_Type__c ,enrtcr__Support_Contract__r.enrtcr__Funding_Management__c ,enrtcr__Support_Contract__r.enrtcr__Client__c ,enrtcr__Category_Item__r.enrtcr__Support_Category_Amount__c ,enrtcr__Category_Item__r.enrtcr__Delivered__c ,enrtcr__Site__c ,enrtcr__Site__r.Name ,enrtcr__Site__r.enrtcr__Site_GL_Code__c ,enrtcr__Service__c ,enrtcr__Service__r.Name ,enrtcr__Site_Service_Program__c ,enrtcr__Rate__c ,enrtcr__Rate__r.Name ,enrtcr__Rate__r.enrtcr__Amount_Ex_GST__c ,enrtcr__Rate__r.enrtcr__Quantity_Type__c ,enrtcr__Rate__r.enrtcr__Allow_Rate_Negotiation__c FROM enrtcr__Support_Contract_Item__c WHERE(" + filterstring + ") AND enrtcr__Support_Contract__r.enrtcr__Status__c = 'Current' ", out qr); //else //{ // var UTCTime = Convert.ToDateTime(lastintegratedDate).ToString("yyyy-MM-dd") + "T" + Convert.ToDateTime(lastintegratedDate).ToString("HH:mm:ss") + "Z"; // ss1.query(sHeader, null, null, null, @"SELECT Id // ,Name // ,enrtcr__Remaining__c // ,enrtcr__Item_Overclaim__c // ,enrtcr__Support_Contract__c // ,enrtcr__Support_Contract__r.Name // ,enrtcr__Support_Contract__r.enrtcr__End_Date__c // ,enrtcr__Support_Contract__r.enrtcr__Status__c // ,enrtcr__Support_Contract__r.enrtcr__Funding_Type__c // ,enrtcr__Support_Contract__r.enrtcr__Funding_Management__c // ,enrtcr__Support_Contract__r.enrtcr__Client__c // ,enrtcr__Category_Item__r.enrtcr__Support_Category_Amount__c // ,enrtcr__Category_Item__r.enrtcr__Delivered__c // ,enrtcr__Site__c // ,enrtcr__Site__r.Name // ,enrtcr__Site__r.enrtcr__Site_GL_Code__c // ,enrtcr__Service__c // ,enrtcr__Service__r.Name // ,enrtcr__Site_Service_Program__c // ,enrtcr__Rate__c // ,enrtcr__Rate__r.Name // ,enrtcr__Rate__r.enrtcr__Amount_Ex_GST__c // ,enrtcr__Rate__r.enrtcr__Quantity_Type__c // ,enrtcr__Rate__r.enrtcr__Allow_Rate_Negotiation__c,LastModifiedDate // FROM enrtcr__Support_Contract_Item__c // WHERE(" + filterstring + ") AND enrtcr__Support_Contract__r.enrtcr__Status__c = 'Current' and LastModifiedDate > YESTERDAY", out qr); //} sObject[] records = qr.records; if (records != null) { if (records.Length > 0) { for (var i = 0; i <= records.Length - 1; i++) { CustomerServiceLine csl = new CustomerServiceLine(); var customerId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Client__c; csl.ServiceAgreementCustomerId = dba.GetCustomerId(customerId); csl.ServiceAgreementId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__c;; csl.ServiceAgreementName = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.Name; csl.ServiceAgreementEndDate = Convert.ToDateTime(((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__End_Date__c); if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Current") { csl.ServiceAgreementStatus = (int)CustomerStatus.Current; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Expired") { csl.ServiceAgreementStatus = (int)CustomerStatus.Expired; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Rollover") { csl.ServiceAgreementStatus = (int)CustomerStatus.Rollover; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Cancelled") { csl.ServiceAgreementStatus = (int)CustomerStatus.Cancelled; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Quote Submitted") { csl.ServiceAgreementStatus = (int)CustomerStatus.QuoteSubmitted; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Status__c == "Client Declined") { csl.ServiceAgreementStatus = (int)CustomerStatus.ClientDeclined; } csl.ServiceAgreementFundingManagement = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Funding_Management__c; csl.ServiceAgreementFundingType = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Support_Contract__r.enrtcr__Funding_Type__c; csl.ServiceAgreementItemId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).Id; csl.ServiceAgreementItemName = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).Name; csl.SupportCategoryAmount = (float)((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Category_Item__r.enrtcr__Support_Category_Amount__c; csl.SupportCategoryDelivered = (float?)((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Category_Item__r.enrtcr__Delivered__c; csl.FundsRemaining = (float?)((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Remaining__c; if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Item_Overclaim__c == "Allow") { csl.ItemOverclaim = (int)ItemOverClaim.Allow; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Item_Overclaim__c == "Warn") { csl.ItemOverclaim = (int)ItemOverClaim.Warn; } if (((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Item_Overclaim__c == "Prevent") { csl.ItemOverclaim = (int)ItemOverClaim.Prevent; } csl.SiteId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Site__c; csl.SiteName = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Site__r.Name; // csl.SiteGlCode = ""; csl.SiteServiceProgramId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Site_Service_Program__c; csl.ServiceId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Service__c; csl.ServiceName = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Service__r.Name; csl.RateId = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Rate__c; csl.RateName = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Rate__r.Name; csl.RateAmount = (float?)((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Rate__r.enrtcr__Amount_Ex_GST__c; csl.RateType = ((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Rate__r.enrtcr__Quantity_Type__c; csl.AllowRateNegotiation = Convert.ToBoolean(((SfServiceRef.enrtcr__Support_Contract_Item__c)qr.records[i]).enrtcr__Rate__r.enrtcr__Allow_Rate_Negotiation__c == null ? false : true); csl.Default = false; ltsCusline.Add(csl); } //Insert record to Database dba.IntegrateCustomerLineinfointoDB(ltsCusline); } result = true; } return(result); }