• Roopa S 1
  • NEWBIE
  • 100 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 39
    Questions
  • 40
    Replies
User-added image
need to add " previous and next" buttons and display only 10 records per page

this is the apex controller i have written

public class popupExt {
    public string accId {get;set;}
    Public contact popUpAcc  {get; set;}     
    public boolean displayPopup {get; set;} 
    public List<Account> lstAccount;
    public Integer countTotalRecords{get;set;}
    public Integer offSetSize = 0;
    public Integer QueryLimit = 10;
     
    
    public popupExt(ApexPages.StandardSetController  stdController) {
    }
    
    public void closePopup() {        
        displayPopup = false;     
    }     
    
    public void showPopup() {        
        displayPopup = true; 
       
        popUpAcc = [SELECT Id, Name, Phone, Email FROM Contact where id =: accId ];
        
    }
        public void SoqlPaginationOffsetController(){
        lstAccount = new List<Account>();
        countTotalRecords = [SELECT count() FROM Account];
    } 
    public List<Account> getAccounts(){
        lstAccount = [SELECT Id, Name, Phone FROM Account ORDER BY Name LIMIT :QueryLimit OFFSET :offSetSize];
        return lstAccount;
    }
    
    public boolean getprv(){
        if(offSetSize > 0)
            return false;
        else
            return true;
    }
    
    public boolean getnxt(){
        if(offSetSize + queryLimit < CountTotalRecords)
            return false;
        else
            return true;
    }
    
    public PageReference nextbtn(){
        offSetSize += queryLimit ;
        return null;
    }
    
    public PageReference prvbtn(){
        offSetSize -= queryLimit ;
        return null;
    }
    
    public PageReference fstbtn(){
        offSetSize = 0;
        return null;
    }
    
    public PageReference endbtn(){
        offSetSize = countTotalRecords - math.mod(countTotalRecords,queryLimit);
        return null;
    }
    
  }

VF page

<apex:page standardController="Account" extensions="popupExt" recordSetVar="accnt" tabStyle="Account"  >  
  
    <apex:form >
        <apex:outputPanel id="tstpopup">
            <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displaypopup}"/>
            <apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displaypopup}">
                    <p>Account Name : {!popUpAcc.Name}</p>
                    <p>Phone : {!popUpAcc.Phone}</p>
                <apex:commandButton value="ok" action="{!closePopup}" rerender="tstpopup"/>
            </apex:outputPanel>
        </apex:outputPanel>
 
        <apex:pageBlock title="Accounts" >
             <apex:pageBlockTable value="{!accnt}" var="ac" >
                <apex:column id="two">
                    <apex:commandButton title="{!ac.id}" value="Click" action="{!showPopup}" rerender="tstpopup">
                        <apex:param name="accId" value="{!ac.id}" assignTo="{!accId}"/>
                    </apex:commandButton>
                </apex:column>
                <apex:column value="{!ac.Name}" />
                <apex:column value="{!ac.AccountNumber}" />
                <apex:column value="{!ac.Type}" />
                <apex:column value="{!ac.Rating}" />
                <apex:column value="{!ac.Phone}" />
                <apex:column value="{!ac.billingCity}" />
                <apex:column value="{!ac.billingCountry}" />
                
            </apex:pageBlockTable>
             <apex:commandButton value="First" action="{!fstbtn}" disabled="{!prv}" reRender="pt,pb" />
            <apex:commandButton value="Previous" action="{!prvbtn}" disabled="{!prv}" reRender="pt,pb" />
            <apex:commandButton value="Next" action="{!nextbtn}" disabled="{!nxt}" reRender="pt,pb" />
            <apex:commandButton value="End" action="{!endbtn}" disabled="{!nxt}" reRender="pt,pb" />
        </apex:pageBlock>
    </apex:form>
     
    <style type="text/css">
        .custPopup{
            background-color: white;
            border-width: 2px;
            border-style: solid;
            z-index: 9999;
            left: 50%;
            padding:10px;
            position: absolute;
            /* These are the 3 css properties you will need to change so the popup 
            displays in the center of the screen. First set the width. Then set 
            margin-left to negative half of what the width is. You can add 
            the height property for a fixed size pop up if you want.*/
            width: 500px;
            margin-left: -250px;
            top:100px;
        }
        .popupBackground{
            background-color:black;
            opacity: 0.20;
            filter: alpha(opacity = 20);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;
        }

    </style>
</apex:page>
1. i need to display accountt and related contacts using visual force page
2. related contact of that particular account should display in pop up.
3. i need to display only 10 records in each page.
4. i should display "PREVIOUS" and "NEXT" buttons to display remaining records
hii i need to display accountt and related contacts using visual force page
1. i need to display accountt and related contacts using visual force page
2. related contact of that particular account should display in pop up.
3. i need to display only 10 records in each page.
4. i should display "PREVIOUS" and "NEXT" buttons to display remaining records
1. i need to display accountt and related contacts using visual force page in the below format.
2.after clicking eye icon the related contact of that particular account should display in pop up.
3. i need to display only 10 records in each page.
4. i should display "PREVIOUS" and "NEXT" buttons to display remaining records
 
1. i need to display accountt and related contacts using visual force page in the below format.
2.after clicking eye icon the related contact of that particular account should display in pop up.
3. i need to display only 10 records in each page.
4. i should display "PREVIOUS" and "NEXT" buttons to display remaining records
User-added image
 i need to display accountt and related contacts using aura component
​​​​​​​ i need to display 10 records in one page and i should display "PREVIOUS" and "NEXT" buttons to display remaining records. plz help me
.

Controller class

public class AccRelatedConC{    
    @AuraEnabled
    public static List<Account> fetchAcc (){
        return [SELECT Id, Name, Phone FROM Account];
          
    }    
    @AuraEnabled
    public static List<Contact> fetchCon (String recordId){
        return [SELECT Id, Name, Phone FROM Contact WHERE AccountId=:recordId];
    }
}

Component

<aura:component controller="AccRelatedConC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/>
    <aura:attribute name="show" type="boolean" default="false"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Accounts</span>
        </h3>
        <br/>
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.accData}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <a onclick="{!c.showCon}" value="{!row}" data-index="{!index}">{!row.Name} </a>
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">{!row.Phone}</div></td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    <aura:if isTrue="{!v.show}">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Related Contact Details</span>
            </h3>
            <br/>
            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                <thead>
                    <tr class="slds-text-heading--label">
                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.conData}" var="row2">
                        <tr>
                            <th scope="row"><div class="slds-truncate" title="{!row2.Name}">{!row2.Name}</div></th>
                            <td><div class="slds-truncate" title="{!row2.Phone}">{!row2.Phone}</div></td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
              <div class="slds-clearfix">
            <div class="slds-page-header" role="banner">
                <div class="slds-float_right">            
                    <lightning:button disabled="{!v.PageNumber == 1}" variant="brand" aura:id="prevPage" label="Prev" onclick="{!c.handlePrev}" />            
                    <lightning:button disabled="{!v.PageNumber == v.TotalPages}" aura:id="nextPage" variant="brand" label="Next" onclick="{!c.handleNext}"/>
                </div>
                <p class="slds-page-header__title">{!v.RecordStart}-{!v.RecordEnd} of {!v.TotalRecords} | Page {!v.PageNumber} of {!v.TotalPages}</p>
            </div>
        </div>
        </div>
    </aura:if>
</aura:component>

controller

({
    doinit : function(component, event, helper) {
        var action = component.get('c.fetchAcc');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.accData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    handleNext: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber++;
        helper.getContactList(component, pageNumber, pageSize);
    },
     
    handlePrev: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber--;
        helper.getContactList(component, pageNumber, pageSize);
    },
    onSelectChange: function(component, event, helper) {
        var page = 1
        var pageSize = component.find("pageSize").get("v.value");
        helper.getContactList(component, page, pageSize);
    },

    
    showCon : function(component, event, helper){
        component.set("v.show",true);
        var idx = event.target.getAttribute('data-index');
        console.log('idx---->>> ' + idx);
        var rowRecord = component.get("v.accData")[idx];
        console.log('rowRecord---->>> ' + JSON.stringify(rowRecord));
        var action = component.get('c.fetchCon');
        action.setParams({recordId : rowRecord.Id});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + JSON.stringify(allValues));
                component.set('v.conData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    }
})

helper

({
    getContactList: function(component, pageNumber, pageSize) {
        var action = component.get("c.getContactData");
        action.setParams({
            "pageNumber": pageNumber,
            "pageSize": pageSize
        });
        action.setCallback(this, function(result) {
            var state = result.getState();
            if (component.isValid() && state === "SUCCESS"){
                var resultData = result.getReturnValue();
                component.set("v.ContactList", resultData.contactList);
                component.set("v.PageNumber", resultData.pageNumber);
                component.set("v.TotalRecords", resultData.totalRecords);
                component.set("v.RecordStart", resultData.recordStart);
                component.set("v.RecordEnd", resultData.recordEnd);
                component.set("v.TotalPages", Math.ceil(resultData.totalRecords / pageSize));
            }
        });
        $A.enqueueAction(action);
    }
})
i need to display 10 records in one page and i should display "PREVIOUS" and "NEXT" buttons to display remaining records. plz help me

Controller class

public class AccRelatedConC{    
    @AuraEnabled
    public static List<Account> fetchAcc (){
        return [SELECT Id, Name, Phone FROM Account];
          
    }    
    @AuraEnabled
    public static List<Contact> fetchCon (String recordId){
        return [SELECT Id, Name, Phone FROM Contact WHERE AccountId=:recordId];
    }
}

Component

<aura:component controller="AccRelatedConC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/>
    <aura:attribute name="show" type="boolean" default="false"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Accounts</span>
        </h3>
        <br/>
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.accData}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <a onclick="{!c.showCon}" value="{!row}" data-index="{!index}">{!row.Name} </a>
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">{!row.Phone}</div></td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    <aura:if isTrue="{!v.show}">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Related Contact Details</span>
            </h3>
            <br/>
            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                <thead>
                    <tr class="slds-text-heading--label">
                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.conData}" var="row2">
                        <tr>
                            <th scope="row"><div class="slds-truncate" title="{!row2.Name}">{!row2.Name}</div></th>
                            <td><div class="slds-truncate" title="{!row2.Phone}">{!row2.Phone}</div></td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
              <div class="slds-clearfix">
            <div class="slds-page-header" role="banner">
                <div class="slds-float_right">            
                    <lightning:button disabled="{!v.PageNumber == 1}" variant="brand" aura:id="prevPage" label="Prev" onclick="{!c.handlePrev}" />            
                    <lightning:button disabled="{!v.PageNumber == v.TotalPages}" aura:id="nextPage" variant="brand" label="Next" onclick="{!c.handleNext}"/>
                </div>
                <p class="slds-page-header__title">{!v.RecordStart}-{!v.RecordEnd} of {!v.TotalRecords} | Page {!v.PageNumber} of {!v.TotalPages}</p>
            </div>
        </div>
        </div>
    </aura:if>
</aura:component>

controller

({
    doinit : function(component, event, helper) {
        var action = component.get('c.fetchAcc');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.accData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    handleNext: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber++;
        helper.getContactList(component, pageNumber, pageSize);
    },
     
    handlePrev: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber--;
        helper.getContactList(component, pageNumber, pageSize);
    },
    onSelectChange: function(component, event, helper) {
        var page = 1
        var pageSize = component.find("pageSize").get("v.value");
        helper.getContactList(component, page, pageSize);
    },

    
    showCon : function(component, event, helper){
        component.set("v.show",true);
        var idx = event.target.getAttribute('data-index');
        console.log('idx---->>> ' + idx);
        var rowRecord = component.get("v.accData")[idx];
        console.log('rowRecord---->>> ' + JSON.stringify(rowRecord));
        var action = component.get('c.fetchCon');
        action.setParams({recordId : rowRecord.Id});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + JSON.stringify(allValues));
                component.set('v.conData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    }
})

helper

({
    getContactList: function(component, pageNumber, pageSize) {
        var action = component.get("c.getContactData");
        action.setParams({
            "pageNumber": pageNumber,
            "pageSize": pageSize
        });
        action.setCallback(this, function(result) {
            var state = result.getState();
            if (component.isValid() && state === "SUCCESS"){
                var resultData = result.getReturnValue();
                component.set("v.ContactList", resultData.contactList);
                component.set("v.PageNumber", resultData.pageNumber);
                component.set("v.TotalRecords", resultData.totalRecords);
                component.set("v.RecordStart", resultData.recordStart);
                component.set("v.RecordEnd", resultData.recordEnd);
                component.set("v.TotalPages", Math.ceil(resultData.totalRecords / pageSize));
            }
        });
        $A.enqueueAction(action);
    }
})
i need to display account details using aura component and i should display only 10 records in one page and i should have 2 buttons that is PREVIOUS PAGE and NEXT PAGE to switch between previous page and next page.How to do this??
this is the test class i have written

@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        SVMXC__Service_Order__c serviceOrderObj2 = new SVMXC__Service_Order__c();
        serviceOrderObj2.closure_status__c= 'test';
        serviceOrderObj2.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj2;
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'closed';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        SVMXC__Service_Order_Line__c lineObj1 = new SVMXC__Service_Order_Line__c();
        lineObj1.Status__c = 'closed';
        lineObj1.SVMXC__Line_Type__c = 'Parts';
        lineObj1.Work_order_status__c = 'closed';
        lineObj1.SVMXC__Service_Order__c = serviceOrderObj.ID ;
        insert lineObj1;
        Test.startTest();
        
         Database.SaveResult result = Database.update(serviceOrderObj, false);
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.',result.getErrors()[0].getMessage());
        Database.SaveResult result1 = Database.update(serviceOrderObj2, false);
        System.assertEquals('No line items',result1.getErrors()[0].getMessage());
        serviceOrderObj.SVMXC__Order_Status__c = 'new';
        update serviceOrderObj;
        //update serviceOrderObj;
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}
this is the test class i have written

@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        SVMXC__Service_Order__c serviceOrderObj2 = new SVMXC__Service_Order__c();
        serviceOrderObj2.closure_status__c= 'test';
        serviceOrderObj2.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj2;
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'closed';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        SVMXC__Service_Order_Line__c lineObj1 = new SVMXC__Service_Order_Line__c();
        lineObj1.Status__c = 'closed';
        lineObj1.SVMXC__Line_Type__c = 'Parts';
        lineObj1.Work_order_status__c = 'closed';
        lineObj1.SVMXC__Service_Order__c = serviceOrderObj.ID ;
        insert lineObj1;
        Test.startTest();
        
         Database.SaveResult result = Database.update(serviceOrderObj, false);
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.',result.getErrors()[0].getMessage());
        Database.SaveResult result1 = Database.update(serviceOrderObj2, false);
        System.assertEquals('No line items',result1.getErrors()[0].getMessage());
        serviceOrderObj.SVMXC__Order_Status__c = 'new';
        update serviceOrderObj;
        //update serviceOrderObj;
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }


Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}

trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}
handler class

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}

trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}

i have written this test class but not getting code coverage

@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }
    
    @isTest static void helperMethodSecond(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
        
    }
}
writing test class for the below code

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}

Trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}
Getting error like...
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []    AND

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []



TEST CLASS
@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }
    
    @isTest static void helperMethodSecond(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
        
    }
}
trigger deleteUserTrigger1 on Task (before delete) {
    Id profileid=Userinfo.getProfileId();  
    profile profilname=[select Name from Profile where id=:profileid];
    for(Task accountDuplicate:Trigger.old){
        if(profilname.Name!='System Administrator'){
            accountDuplicate.addError('No Access for Deletion');                                    
        }    
    }
}*/
public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }
    
    
    
    
}


trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}
1. Whenever a user tries to close a work order(change the order status of work order to closed/completed), ensure that it does not have 0 work detail lines associated
   with it.
   Also, check if any of the work detail lines are in open status, the user should see the error
   that : 'The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.'
   
   Whenever a work order is closed,  on all the related work detail lines,  the Work Order Status(text field) should be updated as : Work Order is closed.
   Also, ensure, once the work order is closed, the user should not be able to modify any of the related work detail lines. The system should restrict the user through a custom validation.  
  
 Also, on successful closure of the work order, the closure status(text field) should display the following info in the same format:
     Start Time of WDL1 : Value
 End Date Time of WDL1 : Value

 Start Time of WDL2 : Value
 End Date Time of WDL2 : Value
 
Need to write test class also for this
There are 3 objects in the instance:
1. Customer: The fields are:
Total No of Location(Number)-
Total No of LocationClosed(Number)
Total No of Location with Flag Down(Number)
 
2. Location(<SVMXC_Site_c> ): The fields are:
Closed(Checkbox)
Flag Down(Checkbox)
 
3. Customer Location
Customer - look up
Location(<SVMXC_Site_c> ) - look up
 
The scenario is as follows:
1. Whenever a Location is closed, the number should be updated in Customer
2. When a flag is down in a Location, the number should be updated in Customer.
3. If a Location and Customer and de-linked or re-linked, the associated numbers should be updated in the Customer
4. If a Location/ Customer Location is deleted the numbers should be associated automatically in the Customer .

This trigger i have done for 2 cases from scenario
Trigger==========================
trigger customertrigger on Customer_Location__c (after insert,after update) {
    if(trigger.isAfter && trigger.isInsert){
    locationHandler3.lochandler(trigger.new);

    if(trigger.isAfter && trigger.isUpdate){
            locationHandler3.lochandler(trigger.new);

    }
}
==================================

Handler class========================
====================================
public class locationHandler3 {
    
public static void lochandler(list<Customer_Location__c> cls){
    list<customer_c> crs=new list<customer_c>();
    set<id> clIds=new set<id>();
        set<id> clIds1=new set<id>();
    for(Customer_Location__c clss:cls){
        clIds.add(clss.customer__c);
         clIds1.add(clss.Location__c);
        system.debug('customer id'+clIds);
                system.debug('location ids'+clIds1);
    }
    integer closednumber=0;
    integer falgnumber=0;
    
    list<customer_c> customers=[select id,Name,Total_No_of_Locationc,Total_No_of_Location_closedc,Total_No_of_Location_with_Flag_Downc from customer_c where id in:clIds];
    list<SVMXC_Sitec> locs=[select id,Flag_Downc,Closedc from SVMXCSite_c where id in :clIds1]  ;
   
    for(customer__c cstr: customers){
         system.debug('customers idss'+cstr.id);
        for(SVMXC_Site_c sites:locs){
            if(sites.Closed__c==true){
                closednumber++;
                system.debug('location which are closed'+sites.Closed__c);
            }else if(sites.Flag_Down__c==true){
              falgnumber++; 
            }
          //  cstr.Total_No_of_Location_c=Customer_Location_c.size();
            cstr.Total_No_of_Location_closed__c=closednumber;
            cstr.Total_No_of_Location_with_Flag_Down__c=falgnumber;
            crs.add(cstr);
        }
    }
    if(crs.size()>0){
        update crs;}
}
}
this is the error im getting while saving the code.
Failed to create createContainerMember for containerId=1dc5f000001ETl9AAG: duplicate value found: MetadataContainerId duplicates value on record with id: 4015f000000pZWq, MetadataContainerId duplicates value on record with id: 4015f000000pZWq


trigger bookTrigger on Books__c (after insert) {
    list<Books__c> listOfBooks1 = new list<Books__c>();
    list<Books__c> listOfBooks = new list<Books__c>();
    Set<ID> setOfId = new Set<ID>();
    for(Books__c book: Trigger.New){
        setOfId.add(book.Id);
    }    
    
    listOfBooks = [SELECt Id,Price__c FROM Books__c WHERE Id IN:setOfId];
    if(listOfBooks.size()>0){
       for(Books__c book: listOfBooks){
            book.Price__c =  book.Price__c - (10/100)*book.Price__c;
            listOfBooks1.add(book);
       }
        
    }
    if(listOfBooks1.size()>0){
       update listOfBooks1;
    }
}
need to write trigger to calculate discount.
example- if the price is 100
after saving price should populate with 10% discount
 
 i need to display accountt and related contacts using aura component
​​​​​​​ i need to display 10 records in one page and i should display "PREVIOUS" and "NEXT" buttons to display remaining records. plz help me
.

Controller class

public class AccRelatedConC{    
    @AuraEnabled
    public static List<Account> fetchAcc (){
        return [SELECT Id, Name, Phone FROM Account];
          
    }    
    @AuraEnabled
    public static List<Contact> fetchCon (String recordId){
        return [SELECT Id, Name, Phone FROM Contact WHERE AccountId=:recordId];
    }
}

Component

<aura:component controller="AccRelatedConC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/>
    <aura:attribute name="show" type="boolean" default="false"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Accounts</span>
        </h3>
        <br/>
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.accData}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <a onclick="{!c.showCon}" value="{!row}" data-index="{!index}">{!row.Name} </a>
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">{!row.Phone}</div></td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    <aura:if isTrue="{!v.show}">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Related Contact Details</span>
            </h3>
            <br/>
            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                <thead>
                    <tr class="slds-text-heading--label">
                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.conData}" var="row2">
                        <tr>
                            <th scope="row"><div class="slds-truncate" title="{!row2.Name}">{!row2.Name}</div></th>
                            <td><div class="slds-truncate" title="{!row2.Phone}">{!row2.Phone}</div></td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
              <div class="slds-clearfix">
            <div class="slds-page-header" role="banner">
                <div class="slds-float_right">            
                    <lightning:button disabled="{!v.PageNumber == 1}" variant="brand" aura:id="prevPage" label="Prev" onclick="{!c.handlePrev}" />            
                    <lightning:button disabled="{!v.PageNumber == v.TotalPages}" aura:id="nextPage" variant="brand" label="Next" onclick="{!c.handleNext}"/>
                </div>
                <p class="slds-page-header__title">{!v.RecordStart}-{!v.RecordEnd} of {!v.TotalRecords} | Page {!v.PageNumber} of {!v.TotalPages}</p>
            </div>
        </div>
        </div>
    </aura:if>
</aura:component>

controller

({
    doinit : function(component, event, helper) {
        var action = component.get('c.fetchAcc');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.accData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    handleNext: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber++;
        helper.getContactList(component, pageNumber, pageSize);
    },
     
    handlePrev: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber--;
        helper.getContactList(component, pageNumber, pageSize);
    },
    onSelectChange: function(component, event, helper) {
        var page = 1
        var pageSize = component.find("pageSize").get("v.value");
        helper.getContactList(component, page, pageSize);
    },

    
    showCon : function(component, event, helper){
        component.set("v.show",true);
        var idx = event.target.getAttribute('data-index');
        console.log('idx---->>> ' + idx);
        var rowRecord = component.get("v.accData")[idx];
        console.log('rowRecord---->>> ' + JSON.stringify(rowRecord));
        var action = component.get('c.fetchCon');
        action.setParams({recordId : rowRecord.Id});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + JSON.stringify(allValues));
                component.set('v.conData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    }
})

helper

({
    getContactList: function(component, pageNumber, pageSize) {
        var action = component.get("c.getContactData");
        action.setParams({
            "pageNumber": pageNumber,
            "pageSize": pageSize
        });
        action.setCallback(this, function(result) {
            var state = result.getState();
            if (component.isValid() && state === "SUCCESS"){
                var resultData = result.getReturnValue();
                component.set("v.ContactList", resultData.contactList);
                component.set("v.PageNumber", resultData.pageNumber);
                component.set("v.TotalRecords", resultData.totalRecords);
                component.set("v.RecordStart", resultData.recordStart);
                component.set("v.RecordEnd", resultData.recordEnd);
                component.set("v.TotalPages", Math.ceil(resultData.totalRecords / pageSize));
            }
        });
        $A.enqueueAction(action);
    }
})
i need to display 10 records in one page and i should display "PREVIOUS" and "NEXT" buttons to display remaining records. plz help me

Controller class

public class AccRelatedConC{    
    @AuraEnabled
    public static List<Account> fetchAcc (){
        return [SELECT Id, Name, Phone FROM Account];
          
    }    
    @AuraEnabled
    public static List<Contact> fetchCon (String recordId){
        return [SELECT Id, Name, Phone FROM Contact WHERE AccountId=:recordId];
    }
}

Component

<aura:component controller="AccRelatedConC"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="PageHeading" type="String" default="Account and Related Contacts" />
    <aura:attribute name="accData" type="List"/>
    <aura:attribute name="conData" type="List"/>
    <aura:attribute name="show" type="boolean" default="false"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doinit}" />
    
    <div class=" slds-page-header slds-text-heading--large slds-align--absolute-center">       
        {!v.PageHeading}              
    </div>
    <div class="slds-section slds-is-open">
        <h3 class="slds-section__title slds-theme_shade">
            <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Accounts</span>
        </h3>
        <br/>
        <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
            <thead>
                <tr class="slds-text-heading--label">
                    <th scope="col"><div class="slds-truncate" title="Account Name">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                </tr>
            </thead>
            <tbody>
                <aura:iteration items="{!v.accData}" var="row" indexVar="index">
                    <tr>
                        <th scope="row">
                            <div class="slds-truncate" >
                                <a onclick="{!c.showCon}" value="{!row}" data-index="{!index}">{!row.Name} </a>
                            </div>
                        </th>
                        <td><div class="slds-truncate" title="{!row.Phone}">{!row.Phone}</div></td>
                    </tr>
                </aura:iteration>
            </tbody>
        </table>
    </div>
    <br/>
    <aura:if isTrue="{!v.show}">
        <div class="slds-section slds-is-open">
            <h3 class="slds-section__title slds-theme_shade">
                <span class="slds-truncate slds-p-horizontal_small" title="Section Title">Related Contact Details</span>
            </h3>
            <br/>
            <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
                <thead>
                    <tr class="slds-text-heading--label">
                        <th scope="col"><div class="slds-truncate" title="Contact Name">Contact Name</div></th>
                        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration items="{!v.conData}" var="row2">
                        <tr>
                            <th scope="row"><div class="slds-truncate" title="{!row2.Name}">{!row2.Name}</div></th>
                            <td><div class="slds-truncate" title="{!row2.Phone}">{!row2.Phone}</div></td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
              <div class="slds-clearfix">
            <div class="slds-page-header" role="banner">
                <div class="slds-float_right">            
                    <lightning:button disabled="{!v.PageNumber == 1}" variant="brand" aura:id="prevPage" label="Prev" onclick="{!c.handlePrev}" />            
                    <lightning:button disabled="{!v.PageNumber == v.TotalPages}" aura:id="nextPage" variant="brand" label="Next" onclick="{!c.handleNext}"/>
                </div>
                <p class="slds-page-header__title">{!v.RecordStart}-{!v.RecordEnd} of {!v.TotalRecords} | Page {!v.PageNumber} of {!v.TotalPages}</p>
            </div>
        </div>
        </div>
    </aura:if>
</aura:component>

controller

({
    doinit : function(component, event, helper) {
        var action = component.get('c.fetchAcc');
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + allValues);
                component.set('v.accData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },
    handleNext: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber++;
        helper.getContactList(component, pageNumber, pageSize);
    },
     
    handlePrev: function(component, event, helper) {
        var pageNumber = component.get("v.PageNumber");  
        var pageSize = component.find("pageSize").get("v.value");
        pageNumber--;
        helper.getContactList(component, pageNumber, pageSize);
    },
    onSelectChange: function(component, event, helper) {
        var page = 1
        var pageSize = component.find("pageSize").get("v.value");
        helper.getContactList(component, page, pageSize);
    },

    
    showCon : function(component, event, helper){
        component.set("v.show",true);
        var idx = event.target.getAttribute('data-index');
        console.log('idx---->>> ' + idx);
        var rowRecord = component.get("v.accData")[idx];
        console.log('rowRecord---->>> ' + JSON.stringify(rowRecord));
        var action = component.get('c.fetchCon');
        action.setParams({recordId : rowRecord.Id});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var allValues = response.getReturnValue();
                console.log("allValues--->>> " + JSON.stringify(allValues));
                component.set('v.conData', allValues);
            }
            else if(state === "ERROR") {
                var errors = response.getError();
                if(errors){
                    if(errors[0] && errors[0].message){
                        console.log("Error Message: " + errors[0].message);
                    }
                }
                else{
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    }
})

helper

({
    getContactList: function(component, pageNumber, pageSize) {
        var action = component.get("c.getContactData");
        action.setParams({
            "pageNumber": pageNumber,
            "pageSize": pageSize
        });
        action.setCallback(this, function(result) {
            var state = result.getState();
            if (component.isValid() && state === "SUCCESS"){
                var resultData = result.getReturnValue();
                component.set("v.ContactList", resultData.contactList);
                component.set("v.PageNumber", resultData.pageNumber);
                component.set("v.TotalRecords", resultData.totalRecords);
                component.set("v.RecordStart", resultData.recordStart);
                component.set("v.RecordEnd", resultData.recordEnd);
                component.set("v.TotalPages", Math.ceil(resultData.totalRecords / pageSize));
            }
        });
        $A.enqueueAction(action);
    }
})
this is the test class i have written

@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        SVMXC__Service_Order__c serviceOrderObj2 = new SVMXC__Service_Order__c();
        serviceOrderObj2.closure_status__c= 'test';
        serviceOrderObj2.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj2;
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'closed';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        SVMXC__Service_Order_Line__c lineObj1 = new SVMXC__Service_Order_Line__c();
        lineObj1.Status__c = 'closed';
        lineObj1.SVMXC__Line_Type__c = 'Parts';
        lineObj1.Work_order_status__c = 'closed';
        lineObj1.SVMXC__Service_Order__c = serviceOrderObj.ID ;
        insert lineObj1;
        Test.startTest();
        
         Database.SaveResult result = Database.update(serviceOrderObj, false);
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.',result.getErrors()[0].getMessage());
        Database.SaveResult result1 = Database.update(serviceOrderObj2, false);
        System.assertEquals('No line items',result1.getErrors()[0].getMessage());
        serviceOrderObj.SVMXC__Order_Status__c = 'new';
        update serviceOrderObj;
        //update serviceOrderObj;
        System.assertEquals('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}
handler class

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}

trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}

i have written this test class but not getting code coverage

@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }
    
    @isTest static void helperMethodSecond(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
        
    }
}
writing test class for the below code

Handler class

public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }    
}

Trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}
Getting error like...
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []    AND

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.: []



TEST CLASS
@isTest
public class WorkOredrTriggerHelperTest {
    @isTest static void helperMethod(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
    }
    
    @isTest static void helperMethodSecond(){
        
        SVMXC__Service_Order__c serviceOrderObj = new SVMXC__Service_Order__c();
        serviceOrderObj.closure_status__c= 'test';
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        insert serviceOrderObj;
        
        
        SVMXC__Service_Order_Line__c lineObj = new SVMXC__Service_Order_Line__c();
        lineObj.Status__c = 'open';
        lineObj.SVMXC__Service_Order__c = serviceOrderObj.ID ; 
        insert lineObj;
        Test.startTest();
        serviceOrderObj.SVMXC__Order_Status__c = 'Closed';
        update serviceOrderObj;
        System.assertNotEquals('closed', serviceOrderObj.SVMXC__Order_Status__c);
        Test.stopTest();
        
        
    }
}
public class WorkOredrTriggerHelper {
    public static void helperMethod(list<SVMXC__Service_Order__c> WorkOrders){
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrders];
        
        
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrders){
            if(wo.SVMXC__Order_Status__c == 'Closed' || wo.SVMXC__Order_Status__c == 'Completed'){
                if(mapLine.get(wo.Id) != null) {
                   boolean flag = false;
                   for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                        if(wd.Status__c=='open'){
                            flag = true;
                        }
                    }
                   if(flag == true) {
                       System.debug('222The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                       wo.addError('The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.');
                   }
                }
                else {
                    System.debug('No items');
                       wo.addError('No line items');
                }
                    
               
            }
        }

    }
    
    public static void updateRelatedLines(list<SVMXC__Service_Order__c> WorkOrdersNew, Map<Id,SVMXC__Service_Order__c> WorkOrdersOld) {
        
        Map<Id,List<SVMXC__Service_Order_Line__c>> mapLine = new Map<Id,List<SVMXC__Service_Order_Line__c>>();
        List<SVMXC__Service_Order_Line__c> lineItems = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order_Line__c> lineItemsToUpdate = new List<SVMXC__Service_Order_Line__c>();
        List<SVMXC__Service_Order__c> workOrdersToUpdate = new List<SVMXC__Service_Order__c>();
        String closureStatus = '';
        Integer countLineItems;
        Map<Id,String> closureStatusMap = new Map<Id,String>();
        
        lineItems = [select id, Status__c, SVMXC__Service_Order__c, Work_order_status__c, SVMXC__Start_Date_and_Time__c, SVMXC__End_Date_and_Time__c  from  SVMXC__Service_Order_Line__c where SVMXC__Service_Order__c in :WorkOrdersNew];
                
        for(SVMXC__Service_Order_Line__c asd : lineItems) {
            if(mapLine.containsKey(asd.SVMXC__Service_Order__c)){
                mapLine.get(asd.SVMXC__Service_Order__c).add(asd);
                continue;
            }
            mapLine.put(asd.SVMXC__Service_Order__c,new List<SVMXC__Service_Order_Line__c>{asd});
        }
        
        for(SVMXC__Service_Order__c wo : WorkOrdersNew){
            closureStatus = '';
            countLineItems = 0;
            if(wo.SVMXC__Order_Status__c != WorkOrdersOld.get(wo.Id).SVMXC__Order_Status__c && wo.SVMXC__Order_Status__c == 'Closed'){
                for(SVMXC__Service_Order_Line__c wd : mapLine.get(wo.Id)){
                    countLineItems = countLineItems + 1;
                    SVMXC__Service_Order_Line__c newLineItem = new SVMXC__Service_Order_Line__c();
                    newLineItem.Id = wd.Id;
                    newLineItem.Work_order_status__c = 'Work Order is Closed';
                    lineItemsToUpdate.add(newLineItem);
                    closureStatus += 'Start time of WDL'+ countLineItems + ' : ' + wd.SVMXC__Start_Date_and_Time__c+'\n';
                    closureStatus += 'End Date time of WDL'+ countLineItems + ' : ' + wd.SVMXC__End_Date_and_Time__c+'\n'+'\n';
                }
                closureStatusMap.put(wo.Id, closureStatus);
                
            }
        }
        
        List<SVMXC__Service_Order__c> workOrders = [SELECT Id, closure_status__c from SVMXC__Service_Order__c where Id in :WorkOrdersNew];
        for(SVMXC__Service_Order__c workOrder : workOrders){
            workOrder.closure_status__c = closureStatusMap.get(workorder.Id);
            workOrdersToUpdate.add(workOrder);
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update lineItemsToUpdate;
        }
        
        if(lineItemsToUpdate != null && lineItemsToUpdate.size() > 0){
            update workOrdersToUpdate;
        }
    }
    
    
    
    
}


trigger

trigger woTriggerrr on SVMXC__Service_Order__c (before insert, before update, after update, after insert) {
    if(trigger.isBefore && trigger.isupdate){
        system.debug('Inside new trigger'+ Trigger.new);
        WorkOredrTriggerHelper.helperMethod(trigger.new);
    }
    
    if(trigger.isAfter && trigger.isupdate){
        system.debug('Inside new trigger after update'+ Trigger.new);
        WorkOredrTriggerHelper.updateRelatedLines(trigger.new, trigger.oldMap);
    }
}
1. Whenever a user tries to close a work order(change the order status of work order to closed/completed), ensure that it does not have 0 work detail lines associated
   with it.
   Also, check if any of the work detail lines are in open status, the user should see the error
   that : 'The work order cannot be closed since there are no associated work detail lines or the related work detail lines are open.'
   
   Whenever a work order is closed,  on all the related work detail lines,  the Work Order Status(text field) should be updated as : Work Order is closed.
   Also, ensure, once the work order is closed, the user should not be able to modify any of the related work detail lines. The system should restrict the user through a custom validation.  
  
 Also, on successful closure of the work order, the closure status(text field) should display the following info in the same format:
     Start Time of WDL1 : Value
 End Date Time of WDL1 : Value

 Start Time of WDL2 : Value
 End Date Time of WDL2 : Value
 
this is the error im getting while saving the code.
Failed to create createContainerMember for containerId=1dc5f000001ETl9AAG: duplicate value found: MetadataContainerId duplicates value on record with id: 4015f000000pZWq, MetadataContainerId duplicates value on record with id: 4015f000000pZWq


trigger bookTrigger on Books__c (after insert) {
    list<Books__c> listOfBooks1 = new list<Books__c>();
    list<Books__c> listOfBooks = new list<Books__c>();
    Set<ID> setOfId = new Set<ID>();
    for(Books__c book: Trigger.New){
        setOfId.add(book.Id);
    }    
    
    listOfBooks = [SELECt Id,Price__c FROM Books__c WHERE Id IN:setOfId];
    if(listOfBooks.size()>0){
       for(Books__c book: listOfBooks){
            book.Price__c =  book.Price__c - (10/100)*book.Price__c;
            listOfBooks1.add(book);
       }
        
    }
    if(listOfBooks1.size()>0){
       update listOfBooks1;
    }
}
need to write trigger to calculate discount.
example- if the price is 100
after saving price should populate with 10% discount
 
 Whenever we enter some amount of money in the Price field and once we click on save button, the value we entered in the Price field is 10% less than the actual price. This is applicable for while both inserting and updating records.
i have Created a field on account as 'summary'(text field). need to Write a trigger for updating the account summary whenever the description of any related case is changed, the account summary be the concatenation of all the related cases
need to write a batch class which will delete all contacts whose related accounts are inactive. First create a checkbox on account as 'Active'.
Hi Team,


Write a batch class for to delete all contacts of accounts where Account field : active__c="yes" ?


Please give me the reply to above scenario....

Regards
Lakshmi