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
Cheryl L @ MercuryCheryl L @ Mercury 

Code Coverage Help needed

I need some help creating a test code or some how making my Class pass Code Coverage - it currently has 0% and I can't deploy to Production.

 

How do I get this Class to pass.

 

public class NewDealerApproval {

    // Author: Cheryl Lefeber

   

    static final Map<String,Approval_Matrix_New_Dealer__c> APPROVAL_MAP_CONST;

   

    static {

        APPROVAL_MAP_CONST = getNewDealerApprovalMap();

    }

   

    private static Map<String,Approval_Matrix_New_Dealer__c> getNewDealerApprovalMap(){

        // build a Map from Reps (concatenated Field Rep and Service Rep) --> Approval Matrix New Dealer record

        Map<String,Approval_Matrix_New_Dealer__c> results = new Map<String,Approval_Matrix_New_Dealer__c>();

        List<Approval_Matrix_New_Dealer__c> records = [select id,name,Reps__c,

        Final_Approver_BDM__c,Final_Approver_TAM__c,Final_Approver_RBD__c,Account_rep__c,

        Final_Approver_FSD__c,Pre_Approver_TAM__c,Pre_Approver_BDM__c  from Approval_Matrix_New_Dealer__c];

        for(Approval_Matrix_New_Dealer__c record : records){

         if (!results.containsKey(record.Reps__c))

 

results.put(record.Reps__c, record);

        }

        return results;

        }

  

       public static void setNewDealerApprovers(Application__c[] applications){

        for (Application__c p:applications){

            if (p.reps__c != null) {

                if ( APPROVAL_MAP_CONST.containsKey(p.Reps__c))

{

                    p.final_approver_BDM__c = APPROVAL_MAP_CONST.get(p.Reps__c).final_approver_BDM__c;

                    p.final_approver_TAM__c = APPROVAL_MAP_CONST.get(p.Reps__c).final_approver_TAM__c;

                    p.final_approver_RBD__c = APPROVAL_MAP_CONST.get(p.Reps__c).final_approver_RBD__c;

                    p.final_approver_FSD__c = APPROVAL_MAP_CONST.get(p.Reps__c).final_approver_FSD__c;

                    p.pre_approver_BDM__c = APPROVAL_MAP_CONST.get(p.Reps__c).pre_approver_BDM__c;

                    p.pre_approver_TAM__c = APPROVAL_MAP_CONST.get(p.Reps__c).pre_approver_TAM__c;

                    p.account_rep__c = APPROVAL_MAP_CONST.get(p.Reps__c).account_rep__c;

               } else {

                    p.final_approver_BDM__c=null;

                    p.final_approver_TAM__c=null;

                    p.final_approver_RBD__c=null;

                    p.final_approver_FSD__c=null;

                    p.pre_approver_BDM__c=null;

                    p.pre_approver_TAM__c=null;

                    p.account_rep__c=null;

 

                }

            }

        }

    }

}

Cheryl L @ MercuryCheryl L @ Mercury
The error on deployment is that my trigger for this only has 0% coverage, but this also has 0% coverage. I wrote other triggers and classes similar to this with no problem; however, this is the first time it's on a Custom Object of "Applications". Is that a problem?
JHayes SDJHayes SD

You posted code for an Apex class.  Triggers are not the same thing; by definition, triggers are bound to objects (Account, MyObject__c) and DML events (before insert, after update, etc).  Test coverage for triggers is calculated based on DML events performed in a test class/method.  If you have an insert trigger (before insert, after insert), write a test that inserts some records where the trigger would prevent the inserts, then write a method where the insert is permitted.  Rinse, repeat. =)