Skip to main content
Hari Prasad Pithani a posé une question dans #Apex
Hello,

I have created  a class and a trigger seperately for a  custom object. They are working good.  I wrote a TESTCLASS to check wehether my class is working or not. TestClass also successfully executed my method in the testClass with 100% code coverage.

Then, my question is , how my testClass can recognise the "class" particularly to test. I didnt call any class/Method in my TestClass to refer my actual logoc.    

 
6 réponses
  1. 30 janv. 2016, 09:37
    First of all, I would really disadvice to write more than one trigger related to the same object (Standard or Custom) because Salesforce never guarantee the order of execution. Maybe first time Trigger1 is executed before Trigger2 and next time Trigger2 is executed before Trigger1. 

    Regarding your question. Using your TestClass and having this code as an example:

     

    //Class code

    public with sharing classA

    {

    public static void method1(myCustomObject__c myObj)

    {

    ...

    }

    public static void method2(myCustomObject__c myObj)

    {

    ...

    }

    }

    And your trigger

    //Trigger code

    trigger myTrigger on myCustomObject__c (before insert)

    {

    for(myCustomObject__c myObj : Trigger.new) //Remember bulkification

    {

    classA.method1(myObj);

    }

    }

    Then only method1 would be covered and method2 will not be covered, so % would not be 100%

    If your trigger is:

     

    //Trigger code

    trigger myTrigger on myCustomObject__c (before insert)

    {

    for(myCustomObject__c myObj : Trigger.new) //Remember bulkification

    {

    classA.method1(myObj);

    classA.method2(myOjb);

    }

    }

    Then your class would be fully covered by the trigger.

    If you also have this class

     

    //Class code

    public with sharing classB

    {

    public static void method3(myCustomObject__c myObj)

    {

    ...

    }

    }

    But you have above trigger, this second class would not be called there so this class would not be covered at all.

    Does it make sense?

     
0/9000