You need to sign in to do that
Don't have an account?
Switching Environments - QA or Production
When testing in QA and switching to Production it was necessary to always reload the web reference in the .Net application. It became a nuciance and so I am posting a solution that we came across.
When starting your .Net application you can place the code below in the Application_Start subroutine of your Global.asax file. Depending on your environment it just switches out part of the URL string to point to either the Sandbox or Production.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
'***** IMPORTANT ******The the section you are changing causes a restart, you needs some additional properties set
'<section restartOnExternalChanges="false" requirePermission="false" />
'appSettings by default is already set to false
'Sforce.Salesforce web ref 'values 'QA = https://test.salesforce.com/services/Soap 'Prod =https://login.salesforce.com/services/Soap
Try
'get current SFDC settings
Dim mySFDCConn As String = ConfigurationManager.AppSettings("Sforce.Salesforce")
'get a handle on the appsetting Sforce entry in web.config
Dim MyConfig As Configuration = Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~")
Dim setting As KeyValueConfigurationElement = CType(MyConfig.AppSettings.Settings("Sforce.Salesforce"), KeyValueConfigurationElement)
If Not setting Is Nothing Then
If Not ConfigurationManager.AppSettings("Level") Is Nothing Then
If ConfigurationManager.AppSettings("Level").Substring(0, 1) = "P" Then
'only update if different so web.config isn't needlessly updated and reloaded locally
If setting.Value.Contains("test") Then
setting.Value = mySFDCConn.Replace("test", "login")
MyConfig.Save()
End If
Else
'qa or not defined
'only update if different so web.config isn't needlessly updated and reloaded locally
If setting.Value.Contains("login") Then
setting.Value = mySFDCConn.Replace("login", "test")
MyConfig.Save()
End If
End If
End If
End If
Catch ex As Exception
End Try
End Sub
It be easier to just edit the app/web.config file and change the service reference to test for the QA instance. I'm not sure why you have decided to perform this task in code.
It is true that you could do that. In our environment there are many developers working on different applications. They may or may not know anything about Salesforce. When they switch the environment to QA they would be forced to figure out why everything was still pointing to production. In other words they would not know enough to change the URL string from login to test. This was just a suggestion. This is what works best for our type of environment. I could not find an answer when I searched and I thought I could help someone else out if they were facing the same issue.
Great ideas. Post the solution here. Thanks.
Check of the following link: Web.Config Transformation.
For windows apps it's a little more difficult as there is no build in way to do XML transformations, but there is a solution: App.config XML Transformation.