You need to sign in to do that
Don't have an account?
krish123
Test class for Trigger
Q.I am new to salesforce test class.Can you please write test class for the below trigger code.
Thanks in advance !
trigger UpdateItselfAccount on Account (After update)
{
if(TriggerHelper.isAccountTriggersAreRunning == false){
List<Account> parentAccounts = new List<Account>();
for(Account currAcc : Trigger.New)
{
if(currAcc.parentId != null)
{
Account acc = new Account();
acc.Id = currAcc.parentId;
acc.Rating = currAcc.Rating;
parentAccounts.add(acc);
}
}
if(parentAccounts.size() > 0)
update parentAccounts;
}
}
Thanks in advance !
trigger UpdateItselfAccount on Account (After update)
{
if(TriggerHelper.isAccountTriggersAreRunning == false){
List<Account> parentAccounts = new List<Account>();
for(Account currAcc : Trigger.New)
{
if(currAcc.parentId != null)
{
Account acc = new Account();
acc.Id = currAcc.parentId;
acc.Rating = currAcc.Rating;
parentAccounts.add(acc);
}
}
if(parentAccounts.size() > 0)
update parentAccounts;
}
}
private class CheckForFunctionality
{
private testMethod void checkForUpdate()
{
Account objParentAccount = new Account(Name = 'Parent');
insert objParentAccount;
Account objChildAccount = new Account(Name = 'Child', ParentId = objParentAccount.Id, Rating = 3);
insert objChildAccount;
objChildAccount.Rating = 4;
update objChildAccount;
}
}
Please try with this code.