Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using log4net;
- using log4net.Config;
- using SFDCtoCRM_Migration.WebReference;
- using System;
- using System.Configuration;
- // Code assumes that you have imported SFDC Enterprise WSDL into your solution
- namespace SFDCtoCRM_Migration
- {
- class Migrate
- {
- private static readonly ILog logger = LogManager.GetLogger(typeof(Migrate));
- static void Main(string[] args)
- {
- DOMConfigurator.Configure();
- string userName = ConfigurationManager.AppSettings.Get("sfdc.username");
- string password = ConfigurationManager.AppSettings.Get("sfdc.password");
- logger.Info("SFDC Username " + userName);
- WebReference.SforceService SfdcBinding = null;
- WebReference.LoginResult CurrentLoginResult = null;
- SfdcBinding = new SforceService();
- try
- {
- CurrentLoginResult = SfdcBinding.login(userName, password);
- //Change the binding to the new endpoint
- SfdcBinding.Url = CurrentLoginResult.serverUrl;
- //Create a new session header object and set the session id to that returned by the login
- SfdcBinding.SessionHeaderValue = new SessionHeader();
- SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;
- DescribeGlobalResult globalResult = SfdcBinding.describeGlobal();
- int length = globalResult.sobjects.Length;
- logger.Debug("Count of Sobjects ::: " + length);
- for (int i = 0; i < length; ++i)
- {
- String sobjname = globalResult.sobjects[i].name;
- logger.Debug("Sobject is ::: " + sobjname);
- int fieldLen = SfdcBinding.describeSObject(sobjname).fields.Length;
- DescribeSObjectResult sobjectResult = SfdcBinding.describeSObject(sobjname);
- String query = "";
- for (int j = 0; j < fieldLen; ++j)
- {
- logger.Debug(" Field is " + sobjectResult.fields[j].name + " - " + sobjectResult.fields[j].type);
- query = query + sobjectResult.fields[j].name;
- if (j != fieldLen - 1)
- {
- query = query + " , ";
- }
- }
- logger.Debug("select " + query + " from " + sobjname);
- }
- }
- catch (Exception e)
- {
- //
- SfdcBinding = null;
- logger.Error(e);
- }
- finally
- {
- if (SfdcBinding != null)
- {
- SfdcBinding.logout();
- SfdcBinding.Dispose();
- SfdcBinding = null;
- }
- }
- logger.Debug("Current OrgID is :: " + CurrentLoginResult.userInfo.organizationId);
- // This will just block things
- logger.Info("Execution completed, hit any key to close this window ..");
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement