0

I have creates a new apex class and imported its WSDL file along with the enterprise WSDL file as a reference into my .net project. The class will create a Rootstock SO header and SO lines in Rootstock. The class functions and creates the new objects in Rootstock when it is executed from an Apex test calss in Salesfroce. I am able to instantiate the new class with its method and everything appears to work from the .net side, I do not receive any error but I also do not create the SO header or lines. I can create Cases in Salesforce using the same bindings and the same Enterprise WSDL. What am I doing wrong. I suspect I am doing something wrong in the bindings. I have checked the permissions on the apex class.

Apex Class

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);
    }
}

VB Code:

 ' 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
        Catch ex As Exception
            Console.WriteLine(ex)
        End Try
3
  • What does the debug log on the Salesforce side show? Feb 25, 2018 at 8:24
  • Are you certain your Console.WriteLine(ex) lines aren't being hit? What is the code behind rstk.SalesOrderAPI.createSalesOrder(sohdr,solines); doing? Feb 26, 2018 at 0:54
  • rstk.SalesOrderAPI.createSalesOrder(sohdr,solines) is a call to an installed package. This same method works when I call it a from a test class in apex. Feb 26, 2018 at 12:18

1 Answer 1

0

I found I had made two mistakes. First I gave the service the same name as the method in my Apex class. Second I imported the Wsdl as a Web service rather than a Web reference. Once I made these two changes I was then able to access the apex class from my .net environment.

Final Code

 Private Function CreateSO(ByRef Sessionheader As InsertSoService.SessionHeader, ByRef PartNumber As String) As String

    Dim Response As String

    Try

        Dim SO As New InsertSoService.SalesOrder_InsertService()
        SO.SessionHeaderValue = Sessionheader
        Response = SO.InsertWebSO(PartNumber)

    Catch ex As Exception

        Return "Failure"

    End Try

    Return Response

End Function

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .