Skip to main content
Hey,

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

EFES_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 EFES_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.

 
7 answers
  1. Apr 1, 2016, 9:39 AM
    Update: When I queried for the order I created in test class, I saw that the Payment_Type__c field was indeed null. That's why test was failing. Hence I re-typed the test class block into as below:

     

    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;

    This did the trick. Class subject to testing is reverted to its original state. But I really want to know why, at first, Payment Type field did not get populated (it's a picklist field). I appreciate any clarification on this.
0/9000