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
Stefanos.ThomaidisStefanos.Thomaidis 

Test Coverage for a trigger 55%. Must be 75%...

Dear all,

 

I have created the following test class to test a trigger that works.  The trigger changes the value on a dependend object's picklist according to the choice of the parent object.

The test reaches only 55%.

It needs to reach 75% coverage.

Below is the test code and way beyod the trigger.

Any suggestions are more than welcome!

 

Test Code:

 

@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);

List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
Location.add(b);
insert Location;
}

test.startTest();
insert accounts;
test.stopTest();
}
}

 

Trigger:

trigger updateactive on Account (after update, after insert){
Location__c[] StatusToUpdate = new Location__c[]{};
for(Account  c : trigger.new ){
for(Location__c cp: [ 
select id,name,Status__c from Location__c  
where Associate__c =:c.id]){
if ( c.Status__c == 'Under Deactivation'){
cp.Status__c = 'Under Deactivation';
}
StatusToUpdate.add(cp);
}
}
if(StatusToUpdate.size()>0) 
update StatusToUpdate;
}

Rajesh SriramuluRajesh Sriramulu

Hi

 

U just insert the Location__c

 

Try this

 

@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);

List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
 
insert b;
}

test.startTest();
insert accounts;
test.stopTest();
}
}

Stefanos.ThomaidisStefanos.Thomaidis

Hi dude,

 

Thanks, I tried it but it keeps giving a 55%.

All the best,

Rajesh SriramuluRajesh Sriramulu

Hi

 

 

Please provide the lines which r not covered.

Stefanos.ThomaidisStefanos.Thomaidis

Hi,

 

I have all the code posted above, the trigger and the test class.

When I give it a run test, it stucks at 55%.

The trigger works fine when I test it manually.

All the best,

topsecretguytopsecretguy

Have you tried using the web interface to run the test? It provides a handy tool to show you which lines of code have not been run.  Navigate to your test class,  hit Run Test,  check the Trigger Code Coverage section and look for your trigger.  Next to it's name,  there's a percentage coverage value that you can click on to get the visual - you'll quickly be able to see which areas you have not covered.

Stefanos.ThomaidisStefanos.Thomaidis

Thanks dude,

 

It gave a good light there...

 

all the best,

ssrssr
plese write real example how to achieve the testcoverege
ssrssr
Hi rajesh, This is somesh, i need some help from you how can i contact you pls reply me salesfor63@gmail.com 9640113288. please send me your details to my mail id