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
vasanth mohanvasanth mohan 

Test class for trigger not increasing coverage

trigger BusinessName on Account( after insert, after update) {
Id AccBid = staticUtil.getRecordTypeId('Account', 'Business');
Id AccCid = staticUtil.getRecordTypeId('Account', 'Corporate');
Id ConBid = staticUtil.getRecordTypeId('Contact', 'Business');
Id ConCid = staticUtil.getRecordTypeId('Contact', 'Corporate');
if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate) && CheckRecursive.runOnce() ) {
list < contact > cont = new list < contact > ();
set < Id > AccId = new set < Id > ();
for (Account ac: trigger.new) {
if (ac.RecordTypeId == AccBid || ac.RecordTypeId == AccCid) {
AccId.add(ac.Id);
}
}
list < contact > updatecontact = new list < contact > ();
list < Account > acnt = [select id, name, business_privacy_flag__c, Corporate_company_name__C, business_name__c, RecordTypeId, (select id, name, lastname, Business_name1__c, contact_Type__c, RecordTypeId, Business_Privacy_Flag__c from contacts) from account where(id In: AccId) and(RecordTypeId = : AccBid or RecordTypeId = : AccCid)];

if (!acnt.isEmpty()) {
for (Account a: acnt) {
if (a.contacts != null) {
for (Contact co: a.contacts)

if (a.Business_Privacy_Flag__c == true && (a.RecordTypeId == AccBid || a.RecordTypeId == AccCid) ) {
co.Business_Name1__c = '';
updatecontact.add(co);

} else if (a.Business_Privacy_Flag__c == false && co.Business_Privacy_Flag__c==false && a.RecordTypeId == AccBid ) {
co.Business_Name1__c = a.Business_Name__c;
updatecontact.add(co);

} else if (a.Business_Privacy_Flag__c == false && co.Business_Privacy_Flag__c== false && a.RecordTypeId == AccCid) {
co.Business_Name1__c = a.Corporate_Company_Name__c;

updatecontact.add(co);


}

}

}
if (updatecontact != null && updatecontact.size() > 0) {
if (!StaticUtil.isContactCallUpdate) {
update updatecontact;
staticutil.isContactCallUpdate=true;
}
}
}

}

}

For this trigger i cant able to get more code coverage. Only 58 % showing.
Please provide solutions .,its high priority.
SRKSRK
ok, 
Please provide the test class that you already written and the screen shot of the line which are covred and which are not
vasanth mohanvasanth mohan
@isTest()
public class testbusinessname{
    private static id AcCid=staticutil.getRecordTypeId('Account', 'Corporate');
    private static id AcBid=staticutil.getRecordTypeId('Account', 'Business');
    private static id CcCid=staticutil.getRecordTypeId('Contact', 'Corporate');
    private static id CcBid=staticutil.getRecordTypeId('Contact', 'Business');
   public static testmethod void businessnametest(){
       
        Account act= new Account();
        act.Name='test';
        act.RecordTypeId=AcCid;
        act.Corporate_Company_Name__c='company';
        insert act;
             
        Contact cont=new Contact();
        cont.LastName='sample';
        cont.RecordTypeId=CcCid;
        cont.AccountId=act.Id;
        cont.Contact_Type__c='Driver';
        insert cont;
       
       act.Business_Privacy_Flag__c=true;
        update act;
  
        cont.Business_Name1__c='';
        update cont;
      
    }
    
}
vasanth mohanvasanth mohan
trigger BusinessName on Account( after insert, after update) {
    Id AccBid = staticUtil.getRecordTypeId('Account', 'Business');
    Id AccCid = staticUtil.getRecordTypeId('Account', 'Corporate');
    Id ConBid = staticUtil.getRecordTypeId('Contact', 'Business');
    Id ConCid = staticUtil.getRecordTypeId('Contact', 'Corporate');
    if (trigger.isAfter && (trigger.isInsert || trigger.isUpdate) && CheckRecursive.runOnce() ) {
        list < contact > cont = new list < contact > ();
        set < Id > AccId = new set < Id > ();
        for (Account ac: trigger.new) {
            if (ac.RecordTypeId == AccBid || ac.RecordTypeId == AccCid) {
                AccId.add(ac.Id);
            }
        }
        list < contact > updatecontact = new list < contact > ();
        
        list < Account > acnt = [select id, name, business_privacy_flag__c, Corporate_company_name__C, business_name__c, RecordTypeId, (select id, lastname, Business_name1__c, contact_Type__c, RecordTypeId, Business_Privacy_Flag__c from contacts) from account where(id In: AccId) and(RecordTypeId = : AccBid or RecordTypeId = : AccCid)];
       
        
        if (!acnt.isEmpty()) {
            for (Account a: acnt) {
                if (a.contacts != null) {
                    for (Contact co: a.contacts){
                 
                        if (a.Business_Privacy_Flag__c == true && (a.RecordTypeId == AccBid || a.RecordTypeId == AccCid) ) {
                            co.Business_Name1__c = '';
                            updatecontact.add(co);

                        }
                            else if (a.Business_Privacy_Flag__c == false && co.Business_Privacy_Flag__c==false && a.RecordTypeId == AccBid ) {
                            co.Business_Name1__c = a.Business_Name__c;
                            updatecontact.add(co);

                        }
                        else if (a.Business_Privacy_Flag__c == false  && co.Business_Privacy_Flag__c== false && a.RecordTypeId == AccCid) {
                            co.Business_Name1__c = a.Corporate_Company_Name__c;

                           updatecontact.add(co);
                        } 
                    }
                }

            }
        }
            if (updatecontact != null && updatecontact.size() > 0) {
                if (!StaticUtil.isContactCallUpdate) {
                    update updatecontact;
                    staticutil.isContactCallUpdate=true;
                }
            }
        

    }

}