You need to sign in to do that
Don't have an account?

can anybody Suggest how to write a Test class for my below class?I am new to Apex coding.plz help me?
public class Notificationserviceclass {
List<Notification__c> notifylist1 = new list<Notification__c>();
List<Notification__c> notifylist2 = new list<Notification__c>();
public void onAfterInsert(Account[] newAccounts){
for(Account accname:newAccounts)
{
Notification__c notifyvar=new Notification__c();
notifyvar.name=accname.name;
notifyvar.Action__c='Add';
notifylist2.add(notifyvar);
}
insert notifylist2;
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
for(Account Acc:newAccounts){
Account oldname = oldMap.get(Acc.Id);
if(Acc.name!=oldname.name){
Notification__c memb = new Notification__c();
memb.name=Acc.name;
memb.Action__c= 'Modify';
notifylist1.add(memb);
}
if(notifylist1.size()>0 && notifylist1.size()!=null)
{
insert notifylist1;
}
}
}
}
List<Notification__c> notifylist1 = new list<Notification__c>();
List<Notification__c> notifylist2 = new list<Notification__c>();
public void onAfterInsert(Account[] newAccounts){
for(Account accname:newAccounts)
{
Notification__c notifyvar=new Notification__c();
notifyvar.name=accname.name;
notifyvar.Action__c='Add';
notifylist2.add(notifyvar);
}
insert notifylist2;
}
public void onAfterUpdate(Account[] newAccounts, map<id, Account> oldMap ){
for(Account Acc:newAccounts){
Account oldname = oldMap.get(Acc.Id);
if(Acc.name!=oldname.name){
Notification__c memb = new Notification__c();
memb.name=Acc.name;
memb.Action__c= 'Modify';
notifylist1.add(memb);
}
if(notifylist1.size()>0 && notifylist1.size()!=null)
{
insert notifylist1;
}
}
}
}
Here is the Test Class you can use :
Mark solved if this helps.
Regards
Medhya Mahajan
All Answers
Here is the Test Class you can use :
Mark solved if this helps.
Regards
Medhya Mahajan
Now my class code coverage has been reached to 100%.Thank you soo much
Have a small doubt how your Test class covered 100% code coverage for my Given class.
In this Test class you have not used my class name .Now how your test class refer my Apex class.plz tell me?
You need not specifically write the name of the Class to achieve the coverage.
My test class is only inserting and updating account record which is the functionality of your class.
I am guessing their might be a trigger on account for which your class is written.
When I insert or update an account in my Test class that trigger is fired causing your class to run and hence it is covered
Regards
Medhya Mahajan