function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rohini Chaudhary 14Rohini Chaudhary 14 

hii all, can someone help in system.assert for this test class????

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();
    }
    
  

}


 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Rohini,

What error you are facing while running this test class and can you confirm the functionality i'e what is expected result so experts can suggest based on it.

Thanks,
 
Rohini Chaudhary 14Rohini Chaudhary 14
*system.assertEquals(invcLines.Invoice_Id__c, * calculateTaxObj.Invoice_Id__c)*;* *I want this in test class ,by reading in Apex class functionality*,but variable not use there so plz can u help