function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RahulRahul 

Hello friends, can you please teach me how to cover this? Thanks in advance

User-added image
Best Answer chosen by Rahul
Vinoth Vijaya BaskerVinoth Vijaya Basker
Hello Rahul,

Write a test method. Inside the test method
1. Insert Order records with all mandatory values for your custom unique id(I assume Orders is parent for OrderlineItem custom object)
2. Insert OrderLineItemRecords
3. Retrieve the Id of inserted orderlineitem records and pass it to your method 'UpdateUniqueIdinOrderLineItem.

Thanks,
Vinoth

All Answers

Vinoth Vijaya BaskerVinoth Vijaya Basker
Hello Rahul,

Write a test method. Inside the test method
1. Insert Order records with all mandatory values for your custom unique id(I assume Orders is parent for OrderlineItem custom object)
2. Insert OrderLineItemRecords
3. Retrieve the Id of inserted orderlineitem records and pass it to your method 'UpdateUniqueIdinOrderLineItem.

Thanks,
Vinoth
This was selected as the best answer
RahulRahul
Thanks for the reply. I did it like his but it does not work. It gives error Method does not exist.

public static testmethod void test3(){
    Account a = new Account(
            name = 'acc',
            Salesman_number__c = '1',
            Debtor_number__c = '123',
            UniqueDebtor__c = '1234',
            Sister_Company__c = false
        );
        insert a;
        
        // create order
        Order__c order = new Order__c(
            Account_Name__c = a.Id,
            Reserve_Allocation__c = false,
            Status_for_EWS__c='MOQ Check'
        );
        insert order;
        
         // create primary crop
        Primary_Crop__c pc1 = new Primary_Crop__c(
            BVC__c = 4,
            Current_Inventory__c = 300,
            Reserved_Stock__c = 20            
        );
        insert pc1;
        
        // create products with SKUs
        Product__c p1=new Product__c();
        p1.Primary_Crop__c = pc1.id;
        p1.name='KANGKONG';
        p1.active__c=true;
        p1.bvc__c=4;
        p1.Crop_Code__c='KANGKONG';
        p1.Product_Abbreviated__c='Kangkong 00004';
        p1.Product_Full_Name__c='Kangkong 00004';
        p1.Product_Name__c='Kangkong';
        p1.Commercial_Name__c='Kangkong';
        p1.Product_Number__c=1;
        
        insert p1;

     SKU__c s1=new SKU__c();
        s1.name='KANGKONG 010 IT PA2 20G IT';
        s1.Company_Code__c='EWIT';
        s1.Fill_weight__c=20;
        s1.Fill_Weight_Unit_Factor__c=0.001;
        s1.Fill_weight_unit_code__c='GR';
        s1.Packaging_Abbrev__c='PA2 4G IT';
        s1.pack_type__c='POUCH';
        s1.Price_Unit_Code__c='KG';
        s1.Price_Unit_Factor__c=1;
        s1.crop__c=p1.id;
        s1.Packaging_Number__c='134';
        s1.UniqueId__c = 'unq1';
        
        insert s1;
        
        // create order line items
        list<OrderLineItem__c> listOLI = new list<OrderLineItem__c>();
        OrderLineItem__c oli1 = new OrderLineItem__c();
            oli1.Order__c = order.Id;
            oli1.Crop__c = p1.Id;
            oli1.SKU__c = s1.Id;
            oli1.Unit_Price__c = 2.00;
            oli1.Quantity__c = 1;
            oli1.UniqueId__c = 'ext1';
            oli1.primaryCropId__c = pc1.id;
        
        listOLI.add(oli1);
        insert listOLI;
        OrderHandler OH = new OrderHandler();
        OH.updateUniqueIdinOrderLineItem(listOLI);
}
Vinoth Vijaya BaskerVinoth Vijaya Basker
Rahul,

OH.updateUniqueIdinOrderLineItem(listOLI);

In the above line you are passing the list listOLI. But, method expects set of Ids. Please pass set of Ids instead of list. 
 
RahulRahul
Thanks for teaching me. I have completed 2 test classes after your help :)