Guest User

Untitled

a guest
Feb 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. Global class SalesOrder_Insert{
  2.  
  3. Webservice Static void InsertWebSO(string PartNumber)
  4. {
  5.  
  6. Decimal LineNumber;
  7. boolean LineFirm;
  8. rstk__soprod__c LineProduct;
  9. Decimal LineQtyOrder;
  10. Decimal LinePrice;
  11. Decimal LineTaxAmount;
  12. Date LineDueDate;
  13. rstk__sydiv__c SalesDiv;
  14. string SoNumber;
  15. rstk__socust__c SoCustomer;
  16.  
  17. SoNumber='K1209';
  18. LineNumber=1;
  19. LineFirm=true;
  20. LineQtyOrder=6;
  21. LineTaxAmount=47.23;
  22. LinePrice=101.99;
  23. LineDueDate=Date.Today() + 10;
  24.  
  25. // identify a sales division for the order
  26. SalesDiv = [select Id, rstk__sydiv_mainsite__c from rstk__sydiv__c where rstk__sydiv_div__c = 'BTN'];
  27.  
  28. //Select Product for sample
  29. LineProduct= [select Id from rstk__soprod__c where
  30. rstk__soprod_prod__c =: PartNumber and rstk__soprod_div__c = :salesDiv.id];
  31.  
  32. //Select Customer
  33. SoCustomer = [Select Id From rstk__socust__c where Name = 'Regal Cinemas Warren East (REG1444)'];
  34.  
  35. // instantiate a new header
  36. rstk__sohdr__c sohdr = new rstk__sohdr__c();
  37.  
  38. //Populate SO Header
  39. sohdr.rstk__sohdr_div__c = SalesDiv.Id;
  40. sohdr.rstk__sohdr_orderdate__c = Date.Today();
  41. rstk__socust__c customer = SoCustomer;
  42. sohdr.rstk__sohdr_custno__c = customer.Id;
  43.  
  44. // add a line
  45. rstk__soline__c[] solines = new rstk__soline__c[] {};
  46. rstk__soline__c line = new rstk__soline__c();
  47. line.rstk__soline_firm__c = true;
  48. line.rstk__soline_line__c = 1;
  49. line.rstk__soline_prod__c = LineProduct.Id;
  50. line.rstk__soline_qtyorder__c = 6;
  51. line.rstk__soline_price__c = 101.99;
  52. line.rstk__soline_taxamount__c = 47.23;
  53. line.rstk__soline_duedate__c = Date.Today() + 10;
  54. line.rstk__soline_shipdiv__c = SalesDiv.Id;
  55. line.rstk__soline_shipsite__c = SalesDiv.rstk__sydiv_mainsite__c;
  56. solines.add(line);
  57. // create the order
  58. rstk.SalesOrderAPI.createSalesOrder(sohdr,solines);
  59. }
  60. }
  61.  
  62. ' Create Salesforce credentials
  63. Dim PasswordToken As String = Password + SecurityToken
  64. Dim SFDCBinding As SforceService = Nothing
  65. Dim CurrentLoginResult As LoginResult = Nothing
  66.  
  67. 'Populate Salesforce credentials
  68. UserName = ConfigurationManager.AppSettings("UserName")
  69. Password = ConfigurationManager.AppSettings("Password")
  70. SecurityToken = ConfigurationManager.AppSettings("SecurityToken")
  71. PasswordToken = Password + SecurityToken
  72. Console.WriteLine("Logging into Saleforce as - " + UserName)
  73.  
  74. 'Create Salesforce Binding
  75. System.Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12
  76. SFDCBinding = New SforceService()
  77. 'Log into Salesforce
  78. CurrentLoginResult = SFDCBinding.login(UserName, PasswordToken)
  79. 'Change binding to new endpoint
  80. SFDCBinding.Url = CurrentLoginResult.serverUrl
  81.  
  82. 'Create a new session header object and set the session id to that returned by the login
  83. SFDCBinding.SessionHeaderValue = New SessionHeader()
  84. SFDCBinding.SessionHeaderValue.sessionId = CurrentLoginResult.sessionId
  85.  
  86. 'Create a new session header object and set the session id to that returned by the login
  87. Dim SessionHeader As New SalesOrderInsert.SessionHeader
  88. SessionHeader.sessionId = CurrentLoginResult.sessionId
  89. Dim CallOptions As New SalesOrderInsert.CallOptions
  90. Dim DebuggingHeader As New SalesOrderInsert.DebuggingHeader
  91. DebuggingHeader.debugLevel = SalesOrderInsert.LogType.Detail
  92. Dim FieldTruncation As New SalesOrderInsert.AllowFieldTruncationHeader
  93.  
  94. 'Call custom Apex class and create new SO header and line
  95. Try
  96. Dim NewSo As New SalesOrderInsert.InsertWebSORequest(SessionHeader, CallOptions, DebuggingHeader, FieldTruncation, "20000d198212r")
  97.  
  98. Catch ex As Exception
  99. Console.WriteLine(ex)
  100. End Try
Add Comment
Please, Sign In to add comment