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
NatureGodNatureGod 

Test Coverageless than 75%

Hi,

 

For the following trigger:

 

trigger UpdateLocationStatusonLocation on Account (After Update) {

for( Account parent: Trigger.new)
{

List<Location__c > children = [ SELECT Id, Associate__c , Status__c from Location__c where Associate__c = :parent.Id];

List<Location__c > childrenToUpdate = new List<Location__c >();

for(Location__c thischild: children )
{
if( thischild.Status__c != parent.Status__c )
{
thischild.Status__c = parent.Status__c ;
childrenToUpdate.add(thischild);
}
}


update childrenToUpdate;


}

}

 

Which works OK in theSandbox and deals with Accounts and a custom childobject.

When we update a picklistin Accounts, it has to update the corrsponding fieldin the Child.

 

The Test Class I wrote is:

 

@istest
public class UpdateLocationStatusonLocationClass{
Private Static testmethod void TesttrgOnArticulo(){
//Insert Participacion__c Record
Account ACC = new Account();
ACC.Associate_s_Title__c = 'TEST';
ACC.Name = 'TEST';
ACC.Status__c = 'Under Deactivation';
Test.startTest();
insert ACC;

 

//Insert Articulo__c Record
for(Integer i = 0; i < 50; i++){
Location__c LOC = new Location__c();
LOC.Associate__c = '001c000000TSO7v';
LOC.Location_Name__c = 'Test';
LOC.Status__c = 'Active';
LOC.Trade_Category__c = 'BANK';
LOC.Subzone__c = 'a0Ec000000AptpX';
LOC.Prefecture__c = 'Attica';
LOC.SubPrefecture__c = 'Central Sector of Athens';
LOC.Municipality__c = 'Athina';
LOC.Locale__c = 'Kerameikos';
LOC.Address_English__c = 'Athina';
LOC.Address__c = 'Kerameikos';
LOC.Phone_Number__c = '56897845';
insert LOC;
update LOC;
}

ACC.Associate_s_Title__c = 'TEST';
ACC.Name = 'TEST';
ACC.Status__c = 'Under Deactivation';


//Insert Participacion__c Record
// ACC.Associate_s_Title__c = 'TEST';
// ACC.Name = 'TEST';
// ACC.Status__c = 'Under Deactivation';
// insert Acc ;

// LOC.Location_Name__c = 'Test';
// LOC.Status__c = 'Active';
// LOC.Trade_Category__c = 'BANK';
// LOC.Subzone__c = 'test';
// LOC.Prefecture__c = 'Attica';
// LOC.SubPrefecture__c = 'Central Sector of Athens';
// LOC.Municipality__c = 'Athina';
// LOC.Locale__c = 'Kerameikos';
// LOC.Address_English__c = 'Athina';
// LOC.Address__c = 'Kerameikos';
// LOC.Phone_Number__c = 56897845;
// update LOC;

ACC.Associate_s_Title__c = 'TEST';
ACC.Name = 'TEST';
ACC.Status__c = 'Under Deactivation';
update Acc;

Test.stopTest();
// List<Location__c > children = [ SELECT Id, Associate__c , Status__c from Location__c where Associate__c = :ACC.Id];
}
}

 

But it does not get a 75%.

 

Any suggestions to nake it deploy in the production please?

 

Best Regards.

Stefanos

digamber.prasaddigamber.prasad

Hi,

 

Your trigger seems incomplete. Can you please paste your complete trigger.

NatureGodNatureGod

Hi,

 

Thanks for replying,

 

This is the complete trigger.

It works fine, what is does is to update the picklsit in the child object with the sane value chosenin the same picklist in Accounts.

I wrote the test classfor this but it does not get a good percentage.

 

All the Best,

Stefanos

Satyendra RawatSatyendra Rawat

Hi,

update the trigger have some correction, your code cause the problem of Governer limit. 

 

trigger UpdateLocationStatusonLocation on Account (After Update) {
List<Location__c > children = [ SELECT Id, Associate__c , Status__c from Location__c where Associate__c in= :trigger.newmap.keyset()];
List<Location__c > childrenToUpdate = new List<Location__c >();
for( Account parent: Trigger.new)
{


for(Location__c thischild: children )
{
if( thischild==parent.id && thischild.Status__c != parent.Status__c )
{
thischild.Status__c = parent.Status__c ;
childrenToUpdate.add(thischild);
}
}


}
update childrenToUpdate;

}