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
venk1255venk1255 

Test class for trigger

Hi Can any one please help me out for this trigger test class

 

Thanks In Advance

 

trigger trgSystemSize on oe_order_lines__c (before Insert, before Update)
{
    Set<String> ords = new Set<String>();
    for(oe_order_lines__c ord : Trigger.New){   
       if (String.isNotBlank(ord.ITEM_NUMBER__c))
             ords.add(ord.ITEM_NUMBER__c );
    }
 
    if(!ords.IsEmpty())
    {
        Map <String, Item__c> actt = new  Map <String, Item__c>();
        for (Item__c act : [SELECT id,Name,Item_ID__c, Product_Type__c, Item_Category_3__c FROM Item__c  WHERE Item_ID__c IN: ords])                            
                               
                              

                            
                            {
                            system.debug('########--actt--> ' + act);
            actt.put(act.Item_ID__c, act);      
        }
 SYSTEM.DEBUG('--actt--> ' + actt);       
        for(oe_order_lines__c ord1: trigger.new)
        {
            if(String.isNotBlank(ord1.ITEM_NUMBER__c) && actt.containskey(ord1.ITEM_NUMBER__c))
            {
                ord1.Item_Number_Order_Line__c = actt.get(ord1.ITEM_NUMBER__c).Id;                              
                      
                                 
                            
                }
            }            
        }        
    }

Santosh KumbarSantosh Kumbar

Create a test records for oe_order_lines__c  in your test method and insert it. That will cover your trigger.

 

Psuedo Code : 

 

@isTest

public class trgSystemSizeTest(){

 

static testMethod void MethodName(){

oe_order_lines__c  ordLines = new oe_order_lines__c();

ordLines.ITEM_NUMBER__c = '******';

//Include all other neccassary fields

ordLines.FIELD1 = '';

.

.

.

 

Insert ordLines;

 

}

 

}