+ Start a Discussion
NatureGodNatureGod 

Get more than 75% Coverage

Hi all,

 

I am posting this again,

I have built the 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 is to update a picklist item in the child object when we change the same picklist in the parent.

This works fine and I do not see any Governance limitation.

 

I have built this test class:

 

@istest
public class UpdateLocationStatusonLocationClass{
Private Static testmethod void TesttrgOnArticulo(){
Test.startTest();
Account ACC = new Account();

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

insert ACC;
id idss=acc.id;

for(Integer i = 0; i < 50; i++){
Location__c LOC = new Location__c();
LOC.Associate__c = idss;
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;
}

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 more than 75% do deploy.

 

Any Suggestions how to make it deploy, please?

 

Best Regards,

Stefanos

Satyendra RawatSatyendra Rawat

Hi,

Below code help you definitily,

 

And Enjoy.

 

 

trigger UpdateLocationStatusonLocation on Account (After Update) {

List<Location__c > children = [ SELECT Id, Associate__c , Status__c from Location__c where Associate__c = :Trigger.newMap.keyset()];
List<Location__c > childrenToUpdate = new List<Location__c >();
for( Account parent: Trigger.new)
{
for(Location__c thischild: children )
{
if(children.Associate__c==parent.Id && thischild.Status__c != parent.Status__c )
{
thischild.Status__c = parent.Status__c ;
childrenToUpdate.add(thischild);
}
}
}
update childrenToUpdate;
}

===================================================================

@istest
public class UpdateLocationStatusonLocationClass{
Private Static testmethod void TesttrgOnArticulo(){
Test.startTest();
Account ACC = new Account();
ACC.Associate_s_Title__c = 'TEST';
ACC.Name = 'TEST';
ACC.Status__c = 'Under Deactivation';
insert ACC;
List<Location__c> lstLoc = new List<Location__c>();
for(Integer i = 0; i < 5; i++){
Location__c LOC = new Location__c();
LOC.Associate__c = ACC.Id;
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';
lstLoc.add(LOC);
}

insert lstLoc;

ACC.Name = 'TEST UPdate';
update ACC;

Test.stopTest();

}
}