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
roshrosh 

trigger? please help me for this test class


public class VConnect_StockAdjTriggerHelper {
    public static void stockOutInventory(List<VConnect_Stock_Adjustment__c> stckAdjList){
        List<VConnect_Stock_Adjustment__c> stockList = [SELECT Id,Name,VConnect_Status__c,
                                                        (SELECT Id,VConnect_Status__c FROM Stock_Adjustment_Line_Items__r)
                                                        FROM VConnect_Stock_Adjustment__c
                                                        WHERE Id IN:stckAdjList];

        List<VConnect_Stock_Adjustment_Line_Item__c> newUpdateList = new List<VConnect_Stock_Adjustment_Line_Item__c>();
        if(!stockList.isEmpty()){
            for(VConnect_Stock_Adjustment__c varStockAdj : stockList){
                for(VConnect_Stock_Adjustment_Line_Item__c varLineItem : varStockAdj.Stock_Adjustment_Line_Items__r){
                    if(varStockAdj.VConnect_Status__c == 'Approved'){
                        varLineItem.VConnect_Status__c = 'Approved';
                        newUpdateList.add(varLineItem);
                    }
                    
                    else if(varStockAdj.VConnect_Status__c == 'Rejected'){
                        varLineItem.VConnect_Status__c = 'Rejected';
                        newUpdateList.add(varLineItem);
                    }
                    
                }
                
            }
        }
        
        if(!newUpdateList.isEmpty()){
            Database.update(newUpdateList);
        }
        
        
    }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi,
Is the VConnect_StockAdjTriggerHelper apex class is calling from trigger?

If yes, try with below code and insert the mandatory fields.
@istest 
public class VConnect_StockAdjTriggerHelper_Test{
 
    static testMethod void testVConnect_Stock()
    {
        VConnect_Stock_Adjustment__c vconnect = new VConnect_Stock_Adjustment__c();
		vconnect.Name = 'Test';
		vconnect.VConnect_Status__c = 'Approved';
		
		insert vconnect;
		
		VConnect_Stock_Adjustment_Line_Item__c salineItems = new VConnect_Stock_Adjustment_Line_Item__c();
		
		salineItems.Name ='test1';
		salineItems.VConnect_Stock_Adjustment__c = vconnect.id;
		
		insert salineItems;

		}
		
   static testMethod void testVConnect_StockRejected()
    {
        VConnect_Stock_Adjustment__c vconnect = new VConnect_Stock_Adjustment__c();
		vconnect.Name = 'Test';
		vconnect.VConnect_Status__c = 'Rejected';
		
		insert vconnect;
		
		VConnect_Stock_Adjustment_Line_Item__c salineItems = new VConnect_Stock_Adjustment_Line_Item__c();
		
		salineItems.Name ='test1';
		salineItems.VConnect_Stock_Adjustment__c = vconnect.id;
		
		insert salineItems;

		}
		
}

If this helps, Please mark it as best answer.

Thanks!!
roshrosh
Yes.. Thank you so much