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
DeveloperDeveloper 

need help on test class for bellow code.trigger

trigger Example on Product2 (before insert,before update,after insert,after update) {

        System.debug('Inside Trigger ** -->');

        Product2TriggerHelper helper = new Product2TriggerHelper();
        if(!System.label.SYS_RunAPTS_ProductTrigger.equalsIgnoreCase('NO')){
            if (Trigger.isInsert && Trigger.isAfter) {
                 try{
                    
                    helper.onAfterInsert(Trigger.New);
                 }catch(Exception ex){
                     system.debug('Exception exists while inserting PriceListItem' + ex.getMessage());
                 }
            }
            if (Trigger.isUpdate && Trigger.isAfter) {
                try{

                    helper.onAfterUpdate(Trigger.New);
                 }catch(Exception ex){
                     system.debug('Exception exists while inserting PriceListItem' + ex.getMessage());
                 }
            }
        }
    }

Thanks in advance.
Best Answer chosen by Developer
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

 
@isTest
public class ExampleTest 
{
    static testMethod void testUpdateAccount() 
	{
        
        Product2 prod = new Product2(Name = 'Laptop X200',    Family = 'Hardware' ,isActive=true);
        insert prod;
        
        update prod;
		
    }
}

Let us know if this will help you
 

All Answers

Sree SalesforceSree Salesforce
@isTest
private class Example _Test
{   static testMethod void TestAccount()
    {
     Example  exp= new Example ();
     exp.Name ='Test';
    insert exp;
     
      exp.Name = 'Test Acc';
     update exp;
   }
}
Amit Chaudhary 8Amit Chaudhary 8
Please check below post to learn about test classes
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

 
@isTest
public class ExampleTest 
{
    static testMethod void testUpdateAccount() 
	{
        
        Product2 prod = new Product2(Name = 'Laptop X200',    Family = 'Hardware' ,isActive=true);
        insert prod;
        
        update prod;
		
    }
}

Let us know if this will help you
 
This was selected as the best answer
DeveloperDeveloper
Hello Amit, 
Thank you for reply, but code covarage is 20%. 
could you please help on 75%. covarage.
Thank you.
Amit Chaudhary 8Amit Chaudhary 8
Please check system label value

label.SYS_RunAPTS_ProductTrigger that should be YES.

Update label and try same test class again and please check which lines are not covered in Developer console
 
DeveloperDeveloper
Hello Amit, 
thank you very much . its working fine 85% code caovarage.