• Rohini Chaudhary 14
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 6
    Replies
Apex class;


public class PaymentTriggerHandler {
public static void runtrigger(){
        System.debug('inside helper class');
        if(trigger.isAfter && trigger.isInsert){
            afterInsert((List<kugo2p__PaymentX__c>)trigger.new,(Map<Id,kugo2p__PaymentX__c>) trigger.oldMap);
        }
         if(trigger.isAfter && trigger.isUpdate){
          //  afterInsert((List<kugo2p__PaymentX__c>)trigger.new,(Map<Id,kugo2p__PaymentX__c>) trigger.oldMap);
        }
        
    }
    
    private static void afterInsert(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap){
         System.debug('debug after insert.....');
        handleAddressChange(newList, oldMap);
    }
    private static void afterUpdate(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap){
         
        handleAddressChange(newList, oldMap);
    }
    
    private static void handleAddressChange(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap)
    {
        Set<Id> addressUpdateSet = new Set<Id>();
        for(kugo2p__PaymentX__c eachPayment : newList){
           
          
          addressUpdateSet.add(eachPayment.kugo2p__Invoice__c);
        } 
        
        System.debug('addressUpdateSet::'+addressUpdateSet);
        if(!addressUpdateSet.isEmpty())
        {
            callVertexFromPlatformEvent(addressUpdateSet);
        }
    }
    //method to call vertex process builder from platform event to calcualte sales tax
    @future
    private static void callVertexFromPlatformEvent(Set<Id> setOfInvoiceLineIds){
        //local variables
        system.debug('here it the Paymentline line 42');
        if(Label.VERTEX_TAX_SWITCH.equalsIgnoreCase('TRUE')){
            List<Calculate_Tax__e>  calcualteTaxList= new List<Calculate_Tax__e>();
            
            //check if the list is not empty
            if(!setOfInvoiceLineIds.isEmpty()){
                //fetching Invoice ids from invoiceLineList
                system.debug('here it the invoiceline line 49');
                List<kugo2p__KugamonInvoiceLine__c> invoiceLineList = [SELECT Id,kugo2p__Invoice__c 
                                                                       FROM kugo2p__KugamonInvoiceLine__c
                                                                       WHERE kugo2p__Invoice__c IN :setOfInvoiceLineIds
                                                                       AND kugo2p__ProductService__r.kugo2p__ProductFamily__c = 'SecureSuite'];
                system.debug('After here it the invoiceline line 49'+invoiceLineList);
                if(!invoiceLineList.isEmpty()){
                    //iterating invoiceLineList records and creating corresponding platform events records
                    for(kugo2p__KugamonInvoiceLine__c eachServiceLine : invoiceLineList){
                        Calculate_Tax__e calculateTaxObj = new Calculate_Tax__e();
                        calculateTaxObj.Trigger_Process__c = TRUE;
                        calculateTaxObj.Invoice_Id__c  = eachServiceLine.Id+'-'+eachServiceLine.kugo2p__Invoice__c;
                        system.debug('here it the InvoiceId' + calculateTaxObj.Invoice_Id__c );
                        //system.assertEquals(invcLines.Invoice_Id__c, calculateTaxObj.Invoice_Id__c
                        calcualteTaxList.add(calculateTaxObj);
                        system.debug('here it the invoiceline');
                    }
                }
                //publishing platform events
                if(!calcualteTaxList.isEmpty())
                    List<Database.SaveResult> results = EventBus.publish(calcualteTaxList);
                    system.debug('here it the Paymentline line 67');
            }
        }
    }
}


Test class;

@isTest
public class PaymentTriggerHandlerTest {
    
    @testsetup
    static void customDataCreateForInvoiceLineTrigger(){
        List<Trigger_Execution__c> customSettingList = new List<Trigger_Execution__c>();
        Trigger_Execution__c customSetting = TestKugamonDataFactory.createCustomSettings('PaymentTrigger');
        customSettingList.add(customSetting);
        Trigger_Execution__c customSetting1 = TestKugamonDataFactory.createCustomSettings('OrderServiceLineTrigger');
        customSettingList.add(customSetting1);
        Trigger_Execution__c customSetting2 = TestKugamonDataFactory.createCustomSettings('OrderTrigger');
        customSettingList.add(customSetting2);
        Trigger_Execution__c customSetting3 = TestKugamonDataFactory.createCustomSettings('InvoiceTrigger');
        customSettingList.add(customSetting3);
        Trigger_Execution__c customSetting4 = TestKugamonDataFactory.createCustomSettings('InvoiceLineTrigger');
        customSettingList.add(customSetting4);
        Trigger_Execution__c customSetting5 = TestKugamonDataFactory.createCustomSettings('AccountTrigger');
        customSettingList.add(customSetting5);
        
        insert customSettingList;
        
    }

    
    @isTest
    public static void testMethod1(){
        Test.startTest();
            //account
            Account testAccount = TestKugamonDataFactory.createAccount();
            Insert testAccount;
            
            //contact
            Contact testContact = TestKugamonDataFactory.createContact(testAccount);
            Insert testContact;
            
            //custom pricebook
            Pricebook2 testCustomPriceBook = TestKugamonDataFactory.createCustomPriceBook();
            Insert testCustomPriceBook;
            
            //kugamon settings
            kugo2p__KugamonSetting__c kugamonSettings = TestKugamonDataFactory.createKugamonSettings(testCustomPriceBook, new kugo2p__Warehouse__c());
            Insert kugamonSettings;
            
            //warehouse
            kugo2p__Warehouse__c testWarehouse = TestKugamonDataFactory.createWarehouse(kugamonSettings);
            Insert testWarehouse;
            
            //additional account info
            kugo2p__AdditionalAccountDetail__c additionalAccountInfo = TestKugamonDataFactory.createAdditionalAccountInfo(testAccount, testWarehouse);
            //insert additionalAccountInfo;
            
            //product
            List<Product2> lstProducts = TestKugamonDataFactory.createProducts();
            Insert lstProducts;

            //create additional product details
            List<kugo2p__AdditionalProductDetail__c> apds=[Select id,Name from kugo2p__AdditionalProductDetail__c where kugo2p__ReferenceProduct__c=:lstProducts[0].id];
            apds[0].kugo2p__Service__c = True;
            apds[0].kugo2p__UnitofTerm__c = 'Year';
            apds[0].kugo2p__ProductFamily__c = 'SecureSuite';
            update apds;
        
           //Create Pricebook Entries
            list<PricebookEntry> lstPricebookEntry = TestKugamonDataFactory.createPricebookEntries(lstProducts, Test.getStandardPricebookId(), testCustomPriceBook);
            Insert lstPricebookEntry;
            
            List<kugo2p__TaxLocation__c> lstTaxLocations = TestKugamonDataFactory.createTaxLocation(testAccount, additionalAccountInfo, kugamonSettings);
            Insert lstTaxLocations;
            
            id RecordType1=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'New'].id;
            
            //opportunity
            Opportunity testOpportunity = TestKugamonDataFactory.createOpportunity(testAccount, testCustomPriceBook, 'Closed/Won');
            testOpportunity.kugo2p__SyncSource__c = 'Primary Order';
            testOpportunity.RecordTypeId=RecordType1;
            Insert testOpportunity;
            
            //Create Opportunity Line Items
            list<OpportunityLineItem> lstOpportunityLineItems = TestKugamonDataFactory.createOpportunityLineItems(testOpportunity, lstPricebookEntry);
            Insert lstOpportunityLineItems;
        
            //order
            id RecordType=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'kugo2p__SalesOrder__c' AND Name = 'New'].id;
            kugo2p__SalesOrder__c testSalesOrder = TestKugamonDataFactory.createSalesOrder(testAccount, testContact, testOpportunity, testCustomPriceBook, testWarehouse);
            testSalesOrder.RecordTypeId=RecordType;
            Insert testSalesOrder;
            
            //invoice
            List<kugo2p__KugamonInvoice__c> testInvoice = TestKugamonDataFactory.createInvoices(testAccount, testSalesOrder);
            testInvoice[0].kugo2p__InvoiceDueDate__c = system.today().addMonths(6);
            testInvoice[0].kugo2p__SalesOrder__c = testSalesOrder.id;
            testInvoice[0].Service_Start_Date__c=system.today().addDays(32);
            Insert testInvoice;
            
            //invoice lines
            List<kugo2p__KugamonInvoiceLine__c> invcLines = TestKugamonDataFactory.createInvliceLines(testSalesOrder,apds[0],testInvoice[0]);
            insert invcLines;
        
            //Create Payments
            List<kugo2p__PaymentX__c> lstPayments = TestKugamonDataFactory.createPayments(testAccount, testContact, testInvoice[0]);            
            Insert lstPayments; 
            
            lstPayments[0].kugo2p__Status__c = 'Completed';
            update lstPayments;
            lstPayments[0].kugo2p__Status__c = 'Test';
            update lstPayments;
            // system.assertEquals(invcLines.Invoice_Id__c, lstpayments.Invoice_Id__c);
            Test.stopTest();
    }
    
  

}


 
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover catch(Exception e) lines
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover 
catch(Exception e) lines
Apex class - 

public with sharing class InvoiceLineTriggerHandler {

    public class InvoiceLineSchedule {
        public Date lineSvcStartDate {get; set;}
        public Date invcLineSvcDeliveryDate {get; set;}
        public String invcScheduleType {get; set;}
    }
    
    public static void runtrigger(List<kugo2p__KugamonInvoiceLine__c> newList, List<kugo2p__KugamonInvoiceLine__c> oldList, Map<id,kugo2p__KugamonInvoiceLine__c> newMap, Map<id,kugo2p__KugamonInvoiceLine__c> oldMap)
    {    
        if(trigger.isAfter && trigger.isInsert) {
            afterInsert(newList,newMap);
        }
    }
    
    private static void afterInsert(List<kugo2p__KugamonInvoiceLine__c> newList, Map<Id,kugo2p__KugamonInvoiceLine__c> newMap) {
        // Update the Service terms on the Invoice level
        updateInvoiceServiceDates (newList, newMap);
    }

    private static void updateInvoiceServiceDates (List<kugo2p__KugamonInvoiceLine__c> newList, Map<Id,kugo2p__KugamonInvoiceLine__c> newMap) {
        Set<Id> invcIds = new Set <Id> ();
        Map<Id,InvoiceLineSchedule> invcScheduleMap = new Map<Id,InvoiceLineSchedule> ();

        for (kugo2p__KugamonInvoiceLine__c eachInvoiceLine: newList) {
            invcIds.add (eachInvoiceLine.kugo2p__Invoice__c);
        }

        List <kugo2p__KugamonInvoiceLine__c> ivcLines = [Select id, kugo2p__Invoice__c , kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c, kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c, kugo2p__SalesOrder__r.kugo2p__BillingFrequency__c, kugo2p__SalesOrder__r.kugo2p__InvoiceSchedule__c from kugo2p__KugamonInvoiceLine__c Where kugo2p__Invoice__c in :invcIds WITH SECURITY_ENFORCED];

        for(kugo2p__KugamonInvoiceLine__c eachInvcLine:ivcLines){

            InvoiceLineSchedule invcSchedule; 
                system.debug('Nandita>>>>>>>>>>>>>>>>>>>>>>'+invcSchedule);
            if (invcScheduleMap.containsKey(eachInvcLine.kugo2p__Invoice__c)) {
                 
            
                invcSchedule = invcScheduleMap.get(eachInvcLine.kugo2p__Invoice__c);

                if (eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c < invcSchedule.lineSvcStartDate) {
                    invcSchedule.lineSvcStartDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c;
                }

                if (eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c > invcSchedule.invcLineSvcDeliveryDate) {
                    invcSchedule.invcLineSvcDeliveryDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c;
                }
            } else {
                invcSchedule = new InvoiceLineSchedule ();
                invcSchedule.lineSvcStartDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c;
                invcSchedule.invcLineSvcDeliveryDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c;
                invcSchedule.invcScheduleType = eachInvcLine.kugo2p__SalesOrder__r.kugo2p__InvoiceSchedule__c;
                invcScheduleMap.put (eachInvcLine.kugo2p__Invoice__c, invcSchedule);
            }
        }

        List <kugo2p__KugamonInvoice__c> invcList = [Select id, Service_Start_Date__c, Service_End_Date__c from kugo2p__KugamonInvoice__c where id in :invcIds WITH SECURITY_ENFORCED];

        List <kugo2p__KugamonInvoice__c> invcListUpdate = new List <kugo2p__KugamonInvoice__c> ();

        for (kugo2p__KugamonInvoice__c eachInvoice : invcList) {
            if (invcScheduleMap.containsKey (eachInvoice.id)) {
                eachInvoice.Service_Start_Date__c = invcScheduleMap.get (eachInvoice.id).lineSvcStartDate;
                eachInvoice.Service_End_Date__c = invcScheduleMap.get (eachInvoice.id).invcLineSvcDeliveryDate;
                invcListUpdate.add (eachInvoice);
            }
        }

        if ( !invcListUpdate.isEmpty () ) {
            // Database.update(invcListUpdate); // Moved to Future Method
            updateInvoices(JSON.serialize(invcListUpdate));
        }  
    }

    @future
    private static void updateInvoices(String invoiceList){
        List<kugo2p__KugamonInvoice__c> lstInvoices = (List<kugo2p__KugamonInvoice__c>)JSON.deserialize(invoiceList, List<kugo2p__KugamonInvoice__c>.class);
        Database.update(lstInvoices);
    } 
}

Test Class:

@isTest
private class InvoiceLineTriggerHandlerTest {
    @isTest
    static void customDataCreateForInvoiceLineTrigger(){
        List <Trigger_Execution__c> triggerExecList = new List <Trigger_Execution__c> ();
         Trigger_Execution__c invoiceLineTriggerCustomSetting = new Trigger_Execution__c (Name = 'InvoiceLineTrigger', is_Execute__c = true);
         Trigger_Execution__c invoiceTriggerCustomSetting = new Trigger_Execution__c (Name = 'InvoiceTrigger', is_Execute__c = true);
         Trigger_Execution__c orderTriggerCustomSetting = new Trigger_Execution__c (Name = 'OrderTrigger', is_Execute__c = true);
        triggerExecList.Add (invoiceLineTriggerCustomSetting);
        triggerExecList.Add (invoiceTriggerCustomSetting);
        triggerExecList.Add (orderTriggerCustomSetting);         
        insert triggerExecList; 
    }

    @isTest
    static void test1() {
       // try{
            customDataCreateForInvoiceLineTrigger();
            Test.startTest();
            //account
            Account testAccount = TestKugamonDataFactory.createAccount();
            Insert testAccount;
            
            //contact
            Contact testContact = TestKugamonDataFactory.createContact(testAccount);
            Insert testContact;
            
            //custom pricebook
            Pricebook2 testCustomPriceBook = TestKugamonDataFactory.createCustomPriceBook();
            Insert testCustomPriceBook;
            
            //kugamon settings
            kugo2p__KugamonSetting__c kugamonSettings = TestKugamonDataFactory.createKugamonSettings(testCustomPriceBook, new kugo2p__Warehouse__c());
            Insert kugamonSettings;
            
            //warehouse
            kugo2p__Warehouse__c testWarehouse = TestKugamonDataFactory.createWarehouse(kugamonSettings);
            Insert testWarehouse;
            
            //additional account info
            kugo2p__AdditionalAccountDetail__c additionalAccountInfo = TestKugamonDataFactory.createAdditionalAccountInfo(testAccount, testWarehouse);
            //insert additionalAccountInfo;
            
            //product
            List<Product2> lstProducts = TestKugamonDataFactory.createProducts();
            Insert lstProducts;

            //Additional Product detail
            kugo2p__AdditionalProductDetail__c apds = new kugo2p__AdditionalProductDetail__c(Name='PROMO 1 Year End User 5,000-9,999 Employees', kugo2p__ProductDescription__c = 'SecureSuite Membership End User 5,000-9,999 Employees',
            kugo2p__ProductFamily__c = 'SecureSuite', kugo2p__ReferenceProduct__c = lstProducts[0].Id, kugo2p__Service__c = true, 
            kugo2p__StandardPrice__c = 10978, kugo2p__UnitCost__c = null, kugo2p__Active__c = true, kugo2p__PrintProductTextandTerms__c = true, 
            kugo2p__KitBundle__c = true, kugo2p__KitBundlePricing__c = 'Member Prices Only', kugo2p__UnitofTerm__c = 'Year', kugo2p__ProductCode__c = 'CIS-SSM-SLTT');
            
            
            //Create Pricebook Entries
            list<PricebookEntry> lstPricebookEntry = TestKugamonDataFactory.createPricebookEntries(lstProducts, Test.getStandardPricebookId(), testCustomPriceBook);
            Insert lstPricebookEntry;
            
            List<kugo2p__TaxLocation__c> lstTaxLocations = TestKugamonDataFactory.createTaxLocation(testAccount, additionalAccountInfo, kugamonSettings);
            Insert lstTaxLocations;
            
            id RecordType1=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'New'].id;
            
            //opportunity
            Opportunity testOpportunity = TestKugamonDataFactory.createOpportunity(testAccount, testCustomPriceBook, 'Closed/Won');
            testOpportunity.kugo2p__SyncSource__c = 'Primary Order';
            testOpportunity.RecordTypeId=RecordType1;
            Insert testOpportunity;
            
            //Create Opportunity Line Items
            list<OpportunityLineItem> lstOpportunityLineItems = TestKugamonDataFactory.createOpportunityLineItems(testOpportunity, lstPricebookEntry);
            Insert lstOpportunityLineItems;
            
            //order
            id RecordType=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'kugo2p__SalesOrder__c' AND Name = 'New'].id;
            kugo2p__SalesOrder__c testSalesOrder = TestKugamonDataFactory.createSalesOrder(testAccount, testContact, testOpportunity, testCustomPriceBook, testWarehouse);
            testSalesOrder.RecordTypeId=RecordType;
            Insert testSalesOrder;
            
            //invoice
            List<kugo2p__KugamonInvoice__c> testInvoice = TestKugamonDataFactory.createInvoices(testAccount, testSalesOrder);
            testInvoice[0].kugo2p__InvoiceDueDate__c = system.today().addMonths(6);
            Insert testInvoice;
            kugo2p__KugamonInvoice__c testInvoice2=[Select id, Opportunity_Record_Type__c, Date_Difference__c     from kugo2p__KugamonInvoice__c where Id=: testInvoice[0].id];
            system.debug('Date difference1-'+testInvoice2.Date_Difference__c);
            
            //invoice lines
            List<kugo2p__KugamonInvoiceLine__c> invcLines = TestKugamonDataFactory.createInvliceLines(testSalesOrder,apds,testInvoice[0]);
            Insert invcLines;
            //system.debug('invoiceLines '+invcLines);
            Test.stopTest();
       /* }catch(DmlException e){
            System.debug('A DML exception has occurred: ' +
                         e.getMessage());
        }  */       
        
        
    }
}
 
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover catch(Exception e) lines
Apex class;


public class PaymentTriggerHandler {
public static void runtrigger(){
        System.debug('inside helper class');
        if(trigger.isAfter && trigger.isInsert){
            afterInsert((List<kugo2p__PaymentX__c>)trigger.new,(Map<Id,kugo2p__PaymentX__c>) trigger.oldMap);
        }
         if(trigger.isAfter && trigger.isUpdate){
          //  afterInsert((List<kugo2p__PaymentX__c>)trigger.new,(Map<Id,kugo2p__PaymentX__c>) trigger.oldMap);
        }
        
    }
    
    private static void afterInsert(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap){
         System.debug('debug after insert.....');
        handleAddressChange(newList, oldMap);
    }
    private static void afterUpdate(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap){
         
        handleAddressChange(newList, oldMap);
    }
    
    private static void handleAddressChange(list<kugo2p__PaymentX__c> newList,Map<Id,kugo2p__PaymentX__c> oldMap)
    {
        Set<Id> addressUpdateSet = new Set<Id>();
        for(kugo2p__PaymentX__c eachPayment : newList){
           
          
          addressUpdateSet.add(eachPayment.kugo2p__Invoice__c);
        } 
        
        System.debug('addressUpdateSet::'+addressUpdateSet);
        if(!addressUpdateSet.isEmpty())
        {
            callVertexFromPlatformEvent(addressUpdateSet);
        }
    }
    //method to call vertex process builder from platform event to calcualte sales tax
    @future
    private static void callVertexFromPlatformEvent(Set<Id> setOfInvoiceLineIds){
        //local variables
        system.debug('here it the Paymentline line 42');
        if(Label.VERTEX_TAX_SWITCH.equalsIgnoreCase('TRUE')){
            List<Calculate_Tax__e>  calcualteTaxList= new List<Calculate_Tax__e>();
            
            //check if the list is not empty
            if(!setOfInvoiceLineIds.isEmpty()){
                //fetching Invoice ids from invoiceLineList
                system.debug('here it the invoiceline line 49');
                List<kugo2p__KugamonInvoiceLine__c> invoiceLineList = [SELECT Id,kugo2p__Invoice__c 
                                                                       FROM kugo2p__KugamonInvoiceLine__c
                                                                       WHERE kugo2p__Invoice__c IN :setOfInvoiceLineIds
                                                                       AND kugo2p__ProductService__r.kugo2p__ProductFamily__c = 'SecureSuite'];
                system.debug('After here it the invoiceline line 49'+invoiceLineList);
                if(!invoiceLineList.isEmpty()){
                    //iterating invoiceLineList records and creating corresponding platform events records
                    for(kugo2p__KugamonInvoiceLine__c eachServiceLine : invoiceLineList){
                        Calculate_Tax__e calculateTaxObj = new Calculate_Tax__e();
                        calculateTaxObj.Trigger_Process__c = TRUE;
                        calculateTaxObj.Invoice_Id__c  = eachServiceLine.Id+'-'+eachServiceLine.kugo2p__Invoice__c;
                        system.debug('here it the InvoiceId' + calculateTaxObj.Invoice_Id__c );
                        //system.assertEquals(invcLines.Invoice_Id__c, calculateTaxObj.Invoice_Id__c
                        calcualteTaxList.add(calculateTaxObj);
                        system.debug('here it the invoiceline');
                    }
                }
                //publishing platform events
                if(!calcualteTaxList.isEmpty())
                    List<Database.SaveResult> results = EventBus.publish(calcualteTaxList);
                    system.debug('here it the Paymentline line 67');
            }
        }
    }
}


Test class;

@isTest
public class PaymentTriggerHandlerTest {
    
    @testsetup
    static void customDataCreateForInvoiceLineTrigger(){
        List<Trigger_Execution__c> customSettingList = new List<Trigger_Execution__c>();
        Trigger_Execution__c customSetting = TestKugamonDataFactory.createCustomSettings('PaymentTrigger');
        customSettingList.add(customSetting);
        Trigger_Execution__c customSetting1 = TestKugamonDataFactory.createCustomSettings('OrderServiceLineTrigger');
        customSettingList.add(customSetting1);
        Trigger_Execution__c customSetting2 = TestKugamonDataFactory.createCustomSettings('OrderTrigger');
        customSettingList.add(customSetting2);
        Trigger_Execution__c customSetting3 = TestKugamonDataFactory.createCustomSettings('InvoiceTrigger');
        customSettingList.add(customSetting3);
        Trigger_Execution__c customSetting4 = TestKugamonDataFactory.createCustomSettings('InvoiceLineTrigger');
        customSettingList.add(customSetting4);
        Trigger_Execution__c customSetting5 = TestKugamonDataFactory.createCustomSettings('AccountTrigger');
        customSettingList.add(customSetting5);
        
        insert customSettingList;
        
    }

    
    @isTest
    public static void testMethod1(){
        Test.startTest();
            //account
            Account testAccount = TestKugamonDataFactory.createAccount();
            Insert testAccount;
            
            //contact
            Contact testContact = TestKugamonDataFactory.createContact(testAccount);
            Insert testContact;
            
            //custom pricebook
            Pricebook2 testCustomPriceBook = TestKugamonDataFactory.createCustomPriceBook();
            Insert testCustomPriceBook;
            
            //kugamon settings
            kugo2p__KugamonSetting__c kugamonSettings = TestKugamonDataFactory.createKugamonSettings(testCustomPriceBook, new kugo2p__Warehouse__c());
            Insert kugamonSettings;
            
            //warehouse
            kugo2p__Warehouse__c testWarehouse = TestKugamonDataFactory.createWarehouse(kugamonSettings);
            Insert testWarehouse;
            
            //additional account info
            kugo2p__AdditionalAccountDetail__c additionalAccountInfo = TestKugamonDataFactory.createAdditionalAccountInfo(testAccount, testWarehouse);
            //insert additionalAccountInfo;
            
            //product
            List<Product2> lstProducts = TestKugamonDataFactory.createProducts();
            Insert lstProducts;

            //create additional product details
            List<kugo2p__AdditionalProductDetail__c> apds=[Select id,Name from kugo2p__AdditionalProductDetail__c where kugo2p__ReferenceProduct__c=:lstProducts[0].id];
            apds[0].kugo2p__Service__c = True;
            apds[0].kugo2p__UnitofTerm__c = 'Year';
            apds[0].kugo2p__ProductFamily__c = 'SecureSuite';
            update apds;
        
           //Create Pricebook Entries
            list<PricebookEntry> lstPricebookEntry = TestKugamonDataFactory.createPricebookEntries(lstProducts, Test.getStandardPricebookId(), testCustomPriceBook);
            Insert lstPricebookEntry;
            
            List<kugo2p__TaxLocation__c> lstTaxLocations = TestKugamonDataFactory.createTaxLocation(testAccount, additionalAccountInfo, kugamonSettings);
            Insert lstTaxLocations;
            
            id RecordType1=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'New'].id;
            
            //opportunity
            Opportunity testOpportunity = TestKugamonDataFactory.createOpportunity(testAccount, testCustomPriceBook, 'Closed/Won');
            testOpportunity.kugo2p__SyncSource__c = 'Primary Order';
            testOpportunity.RecordTypeId=RecordType1;
            Insert testOpportunity;
            
            //Create Opportunity Line Items
            list<OpportunityLineItem> lstOpportunityLineItems = TestKugamonDataFactory.createOpportunityLineItems(testOpportunity, lstPricebookEntry);
            Insert lstOpportunityLineItems;
        
            //order
            id RecordType=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'kugo2p__SalesOrder__c' AND Name = 'New'].id;
            kugo2p__SalesOrder__c testSalesOrder = TestKugamonDataFactory.createSalesOrder(testAccount, testContact, testOpportunity, testCustomPriceBook, testWarehouse);
            testSalesOrder.RecordTypeId=RecordType;
            Insert testSalesOrder;
            
            //invoice
            List<kugo2p__KugamonInvoice__c> testInvoice = TestKugamonDataFactory.createInvoices(testAccount, testSalesOrder);
            testInvoice[0].kugo2p__InvoiceDueDate__c = system.today().addMonths(6);
            testInvoice[0].kugo2p__SalesOrder__c = testSalesOrder.id;
            testInvoice[0].Service_Start_Date__c=system.today().addDays(32);
            Insert testInvoice;
            
            //invoice lines
            List<kugo2p__KugamonInvoiceLine__c> invcLines = TestKugamonDataFactory.createInvliceLines(testSalesOrder,apds[0],testInvoice[0]);
            insert invcLines;
        
            //Create Payments
            List<kugo2p__PaymentX__c> lstPayments = TestKugamonDataFactory.createPayments(testAccount, testContact, testInvoice[0]);            
            Insert lstPayments; 
            
            lstPayments[0].kugo2p__Status__c = 'Completed';
            update lstPayments;
            lstPayments[0].kugo2p__Status__c = 'Test';
            update lstPayments;
            // system.assertEquals(invcLines.Invoice_Id__c, lstpayments.Invoice_Id__c);
            Test.stopTest();
    }
    
  

}


 
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover catch(Exception e) lines
Apex Class:
public with sharing class ChangeOpptyOwnerCtrl {
    private string oppId;
    public Opportunity oppobj {get;set;}
    public boolean isErrInSave {get;set;}
    
    public ChangeOpptyOwnerCtrl(ApexPages.StandardController ctrl){
        oppId = ApexPages.currentPage().getParameters().get('oppId');
        if(oppId != null)
            oppobj = [Select id, Name, OwnerId from Opportunity where id =: oppId limit 1];
    }
    
    public void saveOwner(){
        isErrInSave = false;
        try{
            if(oppobj != null)
                update oppobj;
        }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error , e.getMessage()));
            isErrInSave = true;
        }
    }
}


TestClass:

@isTest
public with sharing class ChangeOpptyOwnerCtrlTest {
    @testSetup
    static void setupTestData(){
        Account acc = TestUtility.createAccount('Test A');
        insert acc;
        Opportunity opp = TestUtility.createOpportunity('@test opp', Date.today(), 'To be Invoiced', acc.id);
        opp.Follow_up_Date__c = date.today();
        insert opp;
    }
    
    testmethod static void saveOwnerTest(){
        Opportunity opp = [Select id from Opportunity limit 1];
        test.startTest();
        
        Test.setCurrentPageReference(new PageReference('Page.ChangeOpptyOwnerPage'));
        System.currentPageReference().getParameters().put('oppId',opp.id);        
        ApexPages.StandardController sc = new ApexPages.StandardController(opp);
        ChangeOpptyOwnerCtrl ctrlObj = new ChangeOpptyOwnerCtrl(sc);
        
        ctrlObj.saveOwner();
        
        test.stopTest();
        
    }
    
}



can any one help me to cover 
catch(Exception e) lines
Apex class - 

public with sharing class InvoiceLineTriggerHandler {

    public class InvoiceLineSchedule {
        public Date lineSvcStartDate {get; set;}
        public Date invcLineSvcDeliveryDate {get; set;}
        public String invcScheduleType {get; set;}
    }
    
    public static void runtrigger(List<kugo2p__KugamonInvoiceLine__c> newList, List<kugo2p__KugamonInvoiceLine__c> oldList, Map<id,kugo2p__KugamonInvoiceLine__c> newMap, Map<id,kugo2p__KugamonInvoiceLine__c> oldMap)
    {    
        if(trigger.isAfter && trigger.isInsert) {
            afterInsert(newList,newMap);
        }
    }
    
    private static void afterInsert(List<kugo2p__KugamonInvoiceLine__c> newList, Map<Id,kugo2p__KugamonInvoiceLine__c> newMap) {
        // Update the Service terms on the Invoice level
        updateInvoiceServiceDates (newList, newMap);
    }

    private static void updateInvoiceServiceDates (List<kugo2p__KugamonInvoiceLine__c> newList, Map<Id,kugo2p__KugamonInvoiceLine__c> newMap) {
        Set<Id> invcIds = new Set <Id> ();
        Map<Id,InvoiceLineSchedule> invcScheduleMap = new Map<Id,InvoiceLineSchedule> ();

        for (kugo2p__KugamonInvoiceLine__c eachInvoiceLine: newList) {
            invcIds.add (eachInvoiceLine.kugo2p__Invoice__c);
        }

        List <kugo2p__KugamonInvoiceLine__c> ivcLines = [Select id, kugo2p__Invoice__c , kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c, kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c, kugo2p__SalesOrder__r.kugo2p__BillingFrequency__c, kugo2p__SalesOrder__r.kugo2p__InvoiceSchedule__c from kugo2p__KugamonInvoiceLine__c Where kugo2p__Invoice__c in :invcIds WITH SECURITY_ENFORCED];

        for(kugo2p__KugamonInvoiceLine__c eachInvcLine:ivcLines){

            InvoiceLineSchedule invcSchedule; 
                system.debug('Nandita>>>>>>>>>>>>>>>>>>>>>>'+invcSchedule);
            if (invcScheduleMap.containsKey(eachInvcLine.kugo2p__Invoice__c)) {
                 
            
                invcSchedule = invcScheduleMap.get(eachInvcLine.kugo2p__Invoice__c);

                if (eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c < invcSchedule.lineSvcStartDate) {
                    invcSchedule.lineSvcStartDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c;
                }

                if (eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c > invcSchedule.invcLineSvcDeliveryDate) {
                    invcSchedule.invcLineSvcDeliveryDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c;
                }
            } else {
                invcSchedule = new InvoiceLineSchedule ();
                invcSchedule.lineSvcStartDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceStart__c;
                invcSchedule.invcLineSvcDeliveryDate = eachInvcLine.kugo2p__ServiceDeliverySchedule__r.kugo2p__DateServiceDelivered__c;
                invcSchedule.invcScheduleType = eachInvcLine.kugo2p__SalesOrder__r.kugo2p__InvoiceSchedule__c;
                invcScheduleMap.put (eachInvcLine.kugo2p__Invoice__c, invcSchedule);
            }
        }

        List <kugo2p__KugamonInvoice__c> invcList = [Select id, Service_Start_Date__c, Service_End_Date__c from kugo2p__KugamonInvoice__c where id in :invcIds WITH SECURITY_ENFORCED];

        List <kugo2p__KugamonInvoice__c> invcListUpdate = new List <kugo2p__KugamonInvoice__c> ();

        for (kugo2p__KugamonInvoice__c eachInvoice : invcList) {
            if (invcScheduleMap.containsKey (eachInvoice.id)) {
                eachInvoice.Service_Start_Date__c = invcScheduleMap.get (eachInvoice.id).lineSvcStartDate;
                eachInvoice.Service_End_Date__c = invcScheduleMap.get (eachInvoice.id).invcLineSvcDeliveryDate;
                invcListUpdate.add (eachInvoice);
            }
        }

        if ( !invcListUpdate.isEmpty () ) {
            // Database.update(invcListUpdate); // Moved to Future Method
            updateInvoices(JSON.serialize(invcListUpdate));
        }  
    }

    @future
    private static void updateInvoices(String invoiceList){
        List<kugo2p__KugamonInvoice__c> lstInvoices = (List<kugo2p__KugamonInvoice__c>)JSON.deserialize(invoiceList, List<kugo2p__KugamonInvoice__c>.class);
        Database.update(lstInvoices);
    } 
}

Test Class:

@isTest
private class InvoiceLineTriggerHandlerTest {
    @isTest
    static void customDataCreateForInvoiceLineTrigger(){
        List <Trigger_Execution__c> triggerExecList = new List <Trigger_Execution__c> ();
         Trigger_Execution__c invoiceLineTriggerCustomSetting = new Trigger_Execution__c (Name = 'InvoiceLineTrigger', is_Execute__c = true);
         Trigger_Execution__c invoiceTriggerCustomSetting = new Trigger_Execution__c (Name = 'InvoiceTrigger', is_Execute__c = true);
         Trigger_Execution__c orderTriggerCustomSetting = new Trigger_Execution__c (Name = 'OrderTrigger', is_Execute__c = true);
        triggerExecList.Add (invoiceLineTriggerCustomSetting);
        triggerExecList.Add (invoiceTriggerCustomSetting);
        triggerExecList.Add (orderTriggerCustomSetting);         
        insert triggerExecList; 
    }

    @isTest
    static void test1() {
       // try{
            customDataCreateForInvoiceLineTrigger();
            Test.startTest();
            //account
            Account testAccount = TestKugamonDataFactory.createAccount();
            Insert testAccount;
            
            //contact
            Contact testContact = TestKugamonDataFactory.createContact(testAccount);
            Insert testContact;
            
            //custom pricebook
            Pricebook2 testCustomPriceBook = TestKugamonDataFactory.createCustomPriceBook();
            Insert testCustomPriceBook;
            
            //kugamon settings
            kugo2p__KugamonSetting__c kugamonSettings = TestKugamonDataFactory.createKugamonSettings(testCustomPriceBook, new kugo2p__Warehouse__c());
            Insert kugamonSettings;
            
            //warehouse
            kugo2p__Warehouse__c testWarehouse = TestKugamonDataFactory.createWarehouse(kugamonSettings);
            Insert testWarehouse;
            
            //additional account info
            kugo2p__AdditionalAccountDetail__c additionalAccountInfo = TestKugamonDataFactory.createAdditionalAccountInfo(testAccount, testWarehouse);
            //insert additionalAccountInfo;
            
            //product
            List<Product2> lstProducts = TestKugamonDataFactory.createProducts();
            Insert lstProducts;

            //Additional Product detail
            kugo2p__AdditionalProductDetail__c apds = new kugo2p__AdditionalProductDetail__c(Name='PROMO 1 Year End User 5,000-9,999 Employees', kugo2p__ProductDescription__c = 'SecureSuite Membership End User 5,000-9,999 Employees',
            kugo2p__ProductFamily__c = 'SecureSuite', kugo2p__ReferenceProduct__c = lstProducts[0].Id, kugo2p__Service__c = true, 
            kugo2p__StandardPrice__c = 10978, kugo2p__UnitCost__c = null, kugo2p__Active__c = true, kugo2p__PrintProductTextandTerms__c = true, 
            kugo2p__KitBundle__c = true, kugo2p__KitBundlePricing__c = 'Member Prices Only', kugo2p__UnitofTerm__c = 'Year', kugo2p__ProductCode__c = 'CIS-SSM-SLTT');
            
            
            //Create Pricebook Entries
            list<PricebookEntry> lstPricebookEntry = TestKugamonDataFactory.createPricebookEntries(lstProducts, Test.getStandardPricebookId(), testCustomPriceBook);
            Insert lstPricebookEntry;
            
            List<kugo2p__TaxLocation__c> lstTaxLocations = TestKugamonDataFactory.createTaxLocation(testAccount, additionalAccountInfo, kugamonSettings);
            Insert lstTaxLocations;
            
            id RecordType1=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'New'].id;
            
            //opportunity
            Opportunity testOpportunity = TestKugamonDataFactory.createOpportunity(testAccount, testCustomPriceBook, 'Closed/Won');
            testOpportunity.kugo2p__SyncSource__c = 'Primary Order';
            testOpportunity.RecordTypeId=RecordType1;
            Insert testOpportunity;
            
            //Create Opportunity Line Items
            list<OpportunityLineItem> lstOpportunityLineItems = TestKugamonDataFactory.createOpportunityLineItems(testOpportunity, lstPricebookEntry);
            Insert lstOpportunityLineItems;
            
            //order
            id RecordType=[SELECT Id,DeveloperName  FROM RecordType WHERE sObjectType = 'kugo2p__SalesOrder__c' AND Name = 'New'].id;
            kugo2p__SalesOrder__c testSalesOrder = TestKugamonDataFactory.createSalesOrder(testAccount, testContact, testOpportunity, testCustomPriceBook, testWarehouse);
            testSalesOrder.RecordTypeId=RecordType;
            Insert testSalesOrder;
            
            //invoice
            List<kugo2p__KugamonInvoice__c> testInvoice = TestKugamonDataFactory.createInvoices(testAccount, testSalesOrder);
            testInvoice[0].kugo2p__InvoiceDueDate__c = system.today().addMonths(6);
            Insert testInvoice;
            kugo2p__KugamonInvoice__c testInvoice2=[Select id, Opportunity_Record_Type__c, Date_Difference__c     from kugo2p__KugamonInvoice__c where Id=: testInvoice[0].id];
            system.debug('Date difference1-'+testInvoice2.Date_Difference__c);
            
            //invoice lines
            List<kugo2p__KugamonInvoiceLine__c> invcLines = TestKugamonDataFactory.createInvliceLines(testSalesOrder,apds,testInvoice[0]);
            Insert invcLines;
            //system.debug('invoiceLines '+invcLines);
            Test.stopTest();
       /* }catch(DmlException e){
            System.debug('A DML exception has occurred: ' +
                         e.getMessage());
        }  */       
        
        
    }
}
 
At the time of refreshing Full Sandbox from Production. Can we still able to access the full sandbox or it's unavailable which the time of refresh?