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
Avinash Dhanke 6Avinash Dhanke 6 

How to crate test class for this apex class..

global class SyncOppLineItem{
   @InvocableMethod
   public static void getSyncItems(List<String> woId) {
    Workorder workO = [select Id,Opportunity_Number__c FROM workorder where id =: woId[0]];
    
    if(workO != null){
        list<workorderlineitem> k= [select id from workorderlineitem where workorderid =: workO.Id];
            list<workorderlineitem> l = new list<workorderlineitem>();
            delete k;
            list<opportunitylineitem> j = [select pricebookentryid from opportunitylineitem where OpportunityId=: workO.Opportunity_Number__c ];
            system.debug('opportunitylineitem' + j);
        if(j.size()>0){
            for(opportunitylineitem n : j){
                l.add(new WorkOrderLineItem(
                    WorkOrderId = woid[0],
                    PricebookEntryId = n.PricebookEntryId
                ));
                
            }
            
            insert l;
    }
        
}




   }
}
Vinit JoganiVinit Jogani
Not sure what problem you are facing. You need to:
1. create data required.
2. Execute the method in startTest() and stopTest()
3. Verify that the required workorderlineitem is deleted
4. verify the required WorkOrderLineItem is created