Notes
Class
public with sharing class updateAcDescTriggerHandler{
public static void updateAcDesc(Set<Id> setAcIds){
List<Account> acList = [SELECT Id, Description
FROM Account
WHERE Id in : setAcIds];
for(Account ac: acList){
ac.Description = ac.Description + ' updated throug future method.';
}
update acList;
}
}
Trigger
trigger pdateAcDescTrigger on Account (after insert, after update) {
if(trigger.isAfter){
if(trigger.isInsert){
updateAcDescTriggerHandler.updateAcDesc(Trigger.newMap.keySet());
}
}
}
Test Class
@isTest
public with sharing class updateAcDescTriggerHandlerTest {
@isTest
private static void testMethodA(){
Account ac1 = new Account();
ac1.name='New Account for Future Method';
ac1.Description='Methods with future annotation must be static';
Account ac2 = new Account();
ac2.name='New Account for Future Method';
ac2.Description='Methods with future annotation must be static';
List<Account> acList = new List<Account>{ac1, ac2};
insert acList;
Set<Id> acIds = new Set<Id>{ac1.id,ac2.Id};
Test.startTest();
updateAcDescTriggerHandler.updateAcDesc(acIds);
Test.stopTest();
List<Account> acListforAssert =[SELECT Id, Description FROM Account];
System.assert(acListforAssert.get(0).Description.contains('future'));
}
}
Code Coverage
Video
Video does not exists.