0

I have the following method in which SOAP webservice is consumed created by wsdl2apex (only necessary part is shown):

public class SendOrder {

    public void SendOrder(string OrderId) {

        // Query for Order
        Order__c Order = [SELECT    Id,
                               Ship_To_SAP_Code__c,
                               Sold_To_SAP_Code__c,
                               Currency__c,
                               Purchase_Order_Number__c,
                               Requested_Shipping_Date__c,
                               Original_Requested_Shipping_Date__c,
                               Shipping_Date_Change_Reason__c,
                               Incoterm__c,
                               Payment_Type__c,
                               Vehicle_Type__c,
                               Palette_Type__c,
                               Additional_Docs__c,
                               Logistics_Company_Phone__c,
                               Logistics_Company_Email__c,
                               Logistics_Company__c,
                               Order_SAP_Code__c,
                               Source_Country_Code__c,
                               Integration_Id__c,
                               Status__c
                               FROM Order__c 
WHERE Id=:OrderId];

.
.
.
.


        // Assign request parameters
.
.
.

        inputIM_Header.INCOTERMS    =   [SELECT Name FROM List_Of_Values__c WHERE Display_Value__c=:Order.Incoterm__c AND Type__c='INCOTERM' LIMIT 1].Name;
        inputIM_Header.PMNTTRMS     =   [SELECT Name FROM List_Of_Values__c WHERE Display_Value__c=:Order.Payment_Type__c AND Type__c='PAYMENT_TYPE' LIMIT 1].Name;          
        system.debug(inputIM_Header.PMNTTRMS);

.
.
.
.


        }


}

I have also created a test class for this code, in which I first create a dataset and then call the above class inside it (again, only necessary part is shown):

@isTest(SeeAllData=true)
private class SendOrder_Test {

    static testMethod void OrderTest() {

        List_Of_Values__c ListOfValue2 = new List_Of_Values__c();
        ListOfValue2.Name = 'INCO';
        ListOfValue2.Display_Value__c = 'Incoterm';
        ListOfValue2.Type__c = 'INCOTERM';
        insert ListOfValue2;
        system.debug('listofvalue2 id = '+ListOfValue2.id);

        List_Of_Values__c ListOfValue3 = new List_Of_Values__c();
        ListOfValue3.Name = 'PMNT';
        ListOfValue3.Display_Value__c = 'Payment';
        ListOfValue3.Type__c = 'PAYMENT_TYPE';
        insert ListOfValue3;
    system.debug('listofvalue3 id = '+ListOfValue3.id);

.
.
.
.


    Order__c Order = new Order__c();
    Order.ShipTo_Account__c = ShipToAccount.Id;
    Order.Currency__c = 'USD';
    Order.Source_Country_Code__c = 'TURKEY';
    Order.Requested_Shipping_Date__c = system.today();
    Order.Original_Requested_Shipping_Date__c = system.today();
    Order.Incoterm__c = 'Incoterm';
    Order.Payment_Type__c = 'Payment';        
    insert Order;
    system.debug('order id = '+Order.id);

.
.
.
.

        Test.startTest();

        SendOrder SendOrderx = new SendOrder();
        SendOrderx.SendOrder(Order.Id);

        Test.stopTest();

.
.
.
.

    }
}

According to the test data, inputIM_Header.INCOTERMS and inputIM_Header.PMNTTRMS queries should not return blank, because I create exact data for both of them. However, when I run the test, INCOTERMS is populated, while PMNTTRMS query does not see the test data and I get the error specified in the title.

I've made a lot of research about that;

  • I had already SeeAllData on, turning it off was no help,
  • I'm on SystemAdmin user so I have all the permissions,
  • I debug all the test data and make sure they all are created on test class,
  • Debugging PMNTRMS returns a data when executed from execute anonymous (testing with org data),
  • Payment_Type__c FLS is OK for SystemAdmin

The fact that bug me most is that INCOTERMS is fine while PMNTTRMS could not be queried.

P.S. I know you are going to tell me to use List instead of a single sObject; you are right, but I am getting NO record from query at this point. I want to solve it first.

Any help is greatly appreciated. Thanks in advance.

1

Are you setting up the webservice mock to return your test response. You can't make callouts from test methods.

  • Yes, I'm doing that. My only problem in the test class is as I described above. When I delete the problematic line in the class, I pass the test and get 85% coverage. – TSunar Apr 1 '16 at 6:24
0

Update: I queried for the Order test data after I inserted it inside the test class, and its Payment_Type__c picklist field was indeed null even though I defined a value for it. The solution I adopted here is: insert the order test record without defining Incoterm__c and Payment_Type__c fields, then query for this Order record, set these fields, and update.

Order__c Order = new Order__c();        
Order.ShipTo_Account__c = ShipToAccount.Id;
Order.Currency__c = 'USD';
Order.Source_Country_Code__c = 'TURKEY';
Order.Requested_Shipping_Date__c = system.today();
Order.Original_Requested_Shipping_Date__c = system.today();
insert Order;

Order__c OrderUpdate = [SELECT Id, Incoterm__c, Payment_Type__c FROM Order__c WHERE Id=:Order.Id];
OrderUpdate.Incoterm__c = 'Incoterm';
OrderUpdate.Payment_Type__c = 'Payment';
update OrderUpdate;

But I really want to know why this Payment Type picklist field did not get a value initially. I'm looking forward to clarifications on that matter.

Thanks

  • 3
    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review – martin Apr 1 '16 at 10:24
  • Hey, thanks for the heads up, but my post can be viewed as a solution to my issue. This is why I chose to put an answer. Cheers – TSunar Apr 1 '16 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.