You need to sign in to do that
Don't have an account?
dcgb2332
How to get code coverage on apex trigger
Here's the code, not sure why it's not working when I've deployed it before...
trigger UpdateAccountName on Task (before update)
{
Map<Id, Task> idAccountTaskMap = new Map<Id, Task>();
for (Task t : Trigger.new) {
if(t.AccountId != null)
idAccountTaskMap.put(t.AccountId, t);
}
if(idAccountTaskMap.isEmpty()) return;
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id = :idAccountTaskMap.keyset()]);
for(Task a : idAccountTaskMap.values())
{
a.Account_Name__c = accountMap.get(a.AccountId).Name;
}
}
trigger UpdateAccountName on Task (before update)
{
Map<Id, Task> idAccountTaskMap = new Map<Id, Task>();
for (Task t : Trigger.new) {
if(t.AccountId != null)
idAccountTaskMap.put(t.AccountId, t);
}
if(idAccountTaskMap.isEmpty()) return;
Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Name FROM Account WHERE Id = :idAccountTaskMap.keyset()]);
for(Task a : idAccountTaskMap.values())
{
a.Account_Name__c = accountMap.get(a.AccountId).Name;
}
}
I have written the test class with 100% code coverage.
<<<<----Apex Trigger---->>>>
<<<<----Test Class---->>>>
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com