Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Global class SalesOrder_Insert{
- Webservice Static void InsertWebSO(string PartNumber)
- {
- Decimal LineNumber;
- boolean LineFirm;
- rstk__soprod__c LineProduct;
- Decimal LineQtyOrder;
- Decimal LinePrice;
- Decimal LineTaxAmount;
- Date LineDueDate;
- rstk__sydiv__c SalesDiv;
- string SoNumber;
- rstk__socust__c SoCustomer;
- SoNumber='K1209';
- LineNumber=1;
- LineFirm=true;
- LineQtyOrder=6;
- LineTaxAmount=47.23;
- LinePrice=101.99;
- LineDueDate=Date.Today() + 10;
- // identify a sales division for the order
- SalesDiv = [select Id, rstk__sydiv_mainsite__c from rstk__sydiv__c where rstk__sydiv_div__c = 'BTN'];
- //Select Product for sample
- LineProduct= [select Id from rstk__soprod__c where
- rstk__soprod_prod__c =: PartNumber and rstk__soprod_div__c = :salesDiv.id];
- //Select Customer
- SoCustomer = [Select Id From rstk__socust__c where Name = 'Regal Cinemas Warren East (REG1444)'];
- // instantiate a new header
- rstk__sohdr__c sohdr = new rstk__sohdr__c();
- //Populate SO Header
- sohdr.rstk__sohdr_div__c = SalesDiv.Id;
- sohdr.rstk__sohdr_orderdate__c = Date.Today();
- rstk__socust__c customer = SoCustomer;
- sohdr.rstk__sohdr_custno__c = customer.Id;
- // add a line
- rstk__soline__c[] solines = new rstk__soline__c[] {};
- rstk__soline__c line = new rstk__soline__c();
- line.rstk__soline_firm__c = true;
- line.rstk__soline_line__c = 1;
- line.rstk__soline_prod__c = LineProduct.Id;
- line.rstk__soline_qtyorder__c = 6;
- line.rstk__soline_price__c = 101.99;
- line.rstk__soline_taxamount__c = 47.23;
- line.rstk__soline_duedate__c = Date.Today() + 10;
- line.rstk__soline_shipdiv__c = SalesDiv.Id;
- line.rstk__soline_shipsite__c = SalesDiv.rstk__sydiv_mainsite__c;
- solines.add(line);
- // create the order
- rstk.SalesOrderAPI.createSalesOrder(sohdr,solines);
- }
- }
- ' Create Salesforce credentials
- Dim PasswordToken As String = Password + SecurityToken
- Dim SFDCBinding As SforceService = Nothing
- Dim CurrentLoginResult As LoginResult = Nothing
- 'Populate Salesforce credentials
- UserName = ConfigurationManager.AppSettings("UserName")
- Password = ConfigurationManager.AppSettings("Password")
- SecurityToken = ConfigurationManager.AppSettings("SecurityToken")
- PasswordToken = Password + SecurityToken
- Console.WriteLine("Logging into Saleforce as - " + UserName)
- 'Create Salesforce Binding
- System.Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12
- SFDCBinding = New SforceService()
- 'Log into Salesforce
- CurrentLoginResult = SFDCBinding.login(UserName, PasswordToken)
- 'Change binding to 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
- 'Create a new session header object and set the session id to that returned by the login
- Dim SessionHeader As New SalesOrderInsert.SessionHeader
- SessionHeader.sessionId = CurrentLoginResult.sessionId
- Dim CallOptions As New SalesOrderInsert.CallOptions
- Dim DebuggingHeader As New SalesOrderInsert.DebuggingHeader
- DebuggingHeader.debugLevel = SalesOrderInsert.LogType.Detail
- Dim FieldTruncation As New SalesOrderInsert.AllowFieldTruncationHeader
- 'Call custom Apex class and create new SO header and line
- Try
- Dim NewSo As New SalesOrderInsert.InsertWebSORequest(SessionHeader, CallOptions, DebuggingHeader, FieldTruncation, "20000d198212r")
- Catch ex As Exception
- Console.WriteLine(ex)
- End Try
Add Comment
Please, Sign In to add comment