0

My Apex class test coverage is just reaching 48% and failing at a particular line, not sure why it is happening as I am providing all the data that is necessary. My test class look like below.

@isTest
global class CustomerAccountFromRecordComboTest {
    @isTest
    static void CreateTestCustomerAccount() {

        List<Account> updateAccount                 = new List<Account>();
        List<User> updateUser                       = new List<User>();
        List<Record_Combination__c> updateCusAccId  = new List<Record_Combination__c>();


        User so                 = new User();
        so.ProfileId            = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id;
        //so.RoleId               = [SELECT Id FROM Role WHERE Name = 'Sales Team East'].Id;
        so.FirstName            = 'SO';
        so.LastName             = 'user';
        so.Email                = 'puser000@amamamaso.com';
        so.Special_Permissions__c = 'Sales Owner';
        so.Username             = 'puser000@amamama.com' + System.currentTimeMillis();
        so.CompanyName          = 'TEST';
        so.Title                = 'title';
        so.Alias                = 'alias';
        so.FederationIdentifier = 'puser000@amamamaso.com';
        so.TimeZoneSidKey       = 'America/Los_Angeles';
        so.EmailEncodingKey     = 'UTF-8';
        so.LanguageLocaleKey    = 'en_US';
        so.LocaleSidKey         = 'en_US';
        insert so;

        updateUser.add(so);

        User sso                 = new User();
        sso.ProfileId            = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id;
        sso.FirstName            = 'SSO';
        sso.LastName             = 'user';
        sso.Email                = 'puser000@amamamasso.com';
        sso.Special_Permissions__c = 'Sales Owner';
        sso.Username             = 'puser000@amamama.com' + System.currentTimeMillis();
        sso.FederationIdentifier = 'puser000@amamamasso.com';
        sso.CompanyName          = 'TEST';
        sso.Title                = 'title';
        sso.Alias                = 'alias';
        sso.TimeZoneSidKey       = 'America/Los_Angeles';
        sso.EmailEncodingKey     = 'UTF-8';
        sso.LanguageLocaleKey    = 'en_US';
        sso.LocaleSidKey         = 'en_US';
        insert sso;

        updateUser.add(sso);

        User am                 = new User();
        am.ProfileId            = [SELECT Id FROM Profile WHERE Name = 'Standard User'].Id;
        am.FirstName            = 'AM';
        am.LastName             = 'user';
        am.Email                = 'puser000@amamamaam.com';
        am.FederationIdentifier = 'puser000@amamamaam.com';
        am.Username             = 'puser000@amamama.com' + System.currentTimeMillis();
        am.CompanyName          = 'TEST';
        am.Title                = 'title';
        am.Alias                = 'alias';
        am.TimeZoneSidKey       = 'America/Los_Angeles';
        am.EmailEncodingKey     = 'UTF-8';
        am.LanguageLocaleKey    = 'en_US';
        am.LocaleSidKey         = 'en_US';
        insert am;

        updateUser.add(am);

        Account acc                    = new Account();
        acc.OwnerId                    = so.Id;
        acc.Name                       = 'Test Account';
        acc.Customer_Success_Manage__c = am.Id;
        acc.netsuite_conn__NetSuite_Id__c = '5678';
        insert acc;

        updateAccount.add(acc);

        Account agc = new Account();
        agc.Name    = 'Test Agency';
        agc.netsuite_conn__NetSuite_Id__c = '4769';
        insert agc;

        updateAccount.add(agc);

        Contact con   = new Contact();
        con.FirstName = 'Test';
        con.LastName  = 'Contact';
        con.Phone     = '9930039303';
        con.AccountId = acc.Id;
        insert con;

        acc.OB_Customer_Contact__c = con.Id;
        // acc.Billing_Notes__c       = 'Test account billing notes';
        update acc;

        agc.OB_Customer_Contact__c = con.Id;
        // agc.Billing_Notes__c       = 'Test agency billing notes';
        update agc;

        Relationship__c rel = new Relationship__c();
        rel.Account_Client__c = acc.Id;
        rel.Agency__c = agc.Id;
        rel.Relationship_Type__c = 'Agency Client';
        rel.Relationship_Status__c = 'Active';
        insert rel;

        Record_Combination__c recCombo = new Record_Combination__c();
        recCombo.Client__c = acc.Id;
        recCombo.Agency__c = agc.Id;
        recCombo.Client_Agency_Relationship__c = rel.Id;
        recCombo.Primary_Sales_Owner__c = so.Id;
        recCombo.Secondary_Sales_Owner__c = sso.Id;
        recCombo.Primary_Sales_Owner_Split_PCT__c = 70.0;
        recCombo.Secondary_Sales_Owner_Split_PCT__c = 30.0;
        recCombo.Record_Combination_Effective_Date__c = Date.today();
        //recCombo.Primary_Sales_Owner_Effective_Date__c = Date.today();
        recCombo.Customer_Success_Manager__c = am.Id;
        recCombo.Combination_Status__c = 'Proposed';
        insert recCombo;

        recCombo.Combination_Status__c = 'Active';
        update recCombo;
        updateCusAccId.add(recCombo);
    }
}

And here is the SFDC_DataObject's CustomerObject class for your reference, which I am using as a wrapper class for the code that you can see in the image below.

public class CustomerObject {
        public Integer parentId;
        public String  sfCustomerId; 
        public String  companyName;
        public String  customerEmail;
        public String  billingEmail;
        public String  billingPhone;
        public String  billingName;
        public String  billingNotes;
        public String  nsCustomerId;

        public CustomerObject() {}

        public CustomerObject(Integer parentId, String sfCustomerId, String companyName, String customerEmail, String billingEmail, String billingPhone, String billingName, String billingNotes, String nsCustomerId)
        {
            this.parentId      = parentId;
            this.sfCustomerId  = sfCustomerId;
            this.companyName   = companyName;
            this.customerEmail = customerEmail;
            this.billingEmail  = billingEmail;
            this.billingPhone  = billingPhone;
            this.billingName   = billingName;
            this.billingNotes  = billingNotes;
            this.nsCustomerId  = nsCustomerId;
        }
    }

I am adding an image below to show the line where the coverage of my apex class is halting. Please let me know what I might be doing wrong, and please let me know if you need any more details. Thanks in advance.

enter image description here

3
  • Please, look at SFDC_DataObject class and find the exact line, where the code fails. If there is no FATAL_ERROR in logs after running test, then it will be seen with test coverage. Jul 15 at 7:58
  • @MariiaIllarionova Thanks for the response. I Just checked the Wrapper class too as you had mentioned but couldn't find any difference there. I have edited the question and added that too for your reference. Will enable debug logs and check if I can find anything. Please let me know if you think I should be changing something or looking into something particularly. Jul 15 at 8:09
  • @MariiaIllarionova After enabling the debug logs I was able to find out that I had added the field netsuite_conn__NetSuite_Id__c without querying it. After adding that to the query I was able to get the necessary coverage. Thank you for the help, if you can add your comment as answer, I'll accept that. Jul 15 at 8:16
2

As you have found from debug logs, the problem was with netsuite_conn__NetSuite_Id__c field, that was used without querying it in the first place.

However, for the general usefulness of this question for the community, I want to add some tips:

  • Check DEBUG_LOG when running your tests.
  • If log is not available, you can detect the problem place via code coverage, where it stops unpredictably.
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.