Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using log4net;
  2. using log4net.Config;
  3. using SFDCtoCRM_Migration.WebReference;
  4. using System;
  5. using System.Configuration;
  6. // Code assumes that you have imported SFDC Enterprise WSDL into your solution
  7. namespace SFDCtoCRM_Migration
  8. {
  9. class Migrate
  10. {
  11. private static readonly ILog logger = LogManager.GetLogger(typeof(Migrate));
  12. static void Main(string[] args)
  13. {
  14. DOMConfigurator.Configure();
  15.  
  16. string userName = ConfigurationManager.AppSettings.Get("sfdc.username");
  17. string password = ConfigurationManager.AppSettings.Get("sfdc.password");
  18. logger.Info("SFDC Username " + userName);
  19. WebReference.SforceService SfdcBinding = null;
  20. WebReference.LoginResult CurrentLoginResult = null;
  21. SfdcBinding = new SforceService();
  22. try
  23. {
  24. CurrentLoginResult = SfdcBinding.login(userName, password);
  25. //Change the binding to the new endpoint
  26. SfdcBinding.Url = CurrentLoginResult.serverUrl;
  27.  
  28. //Create a new session header object and set the session id to that returned by the login
  29. SfdcBinding.SessionHeaderValue = new SessionHeader();
  30. SfdcBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId;
  31. DescribeGlobalResult globalResult = SfdcBinding.describeGlobal();
  32. int length = globalResult.sobjects.Length;
  33. logger.Debug("Count of Sobjects ::: " + length);
  34. for (int i = 0; i < length; ++i)
  35. {
  36. String sobjname = globalResult.sobjects[i].name;
  37. logger.Debug("Sobject is ::: " + sobjname);
  38. int fieldLen = SfdcBinding.describeSObject(sobjname).fields.Length;
  39. DescribeSObjectResult sobjectResult = SfdcBinding.describeSObject(sobjname);
  40. String query = "";
  41. for (int j = 0; j < fieldLen; ++j)
  42. {
  43. logger.Debug(" Field is " + sobjectResult.fields[j].name + " - " + sobjectResult.fields[j].type);
  44. query = query + sobjectResult.fields[j].name;
  45. if (j != fieldLen - 1)
  46. {
  47. query = query + " , ";
  48. }
  49. }
  50. logger.Debug("select " + query + " from " + sobjname);
  51. }
  52.  
  53. }
  54. catch (Exception e)
  55. {
  56. //
  57. SfdcBinding = null;
  58. logger.Error(e);
  59. }
  60. finally
  61. {
  62. if (SfdcBinding != null)
  63. {
  64. SfdcBinding.logout();
  65. SfdcBinding.Dispose();
  66. SfdcBinding = null;
  67. }
  68. }
  69. logger.Debug("Current OrgID is :: " + CurrentLoginResult.userInfo.organizationId);
  70. // This will just block things
  71. logger.Info("Execution completed, hit any key to close this window ..");
  72. Console.Read();
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement