You need to sign in to do that
Don't have an account?
Adminuser
I need test class following trigger
Hi,
can any one help test class for following trigger
trigger CaseMilestone on Case (after update) {
try{
set <Id> caseIds =new set <Id>();
list<Commision__c> Comlist =new list<Commision__c>();
for(case c:trigger.new)
{
if(c.Status == 'closed' && c.Milestone_Approval_Status__c ==TRUE){
caseIds.add(c.id);
}
}
system.debug('caseIds :'+caseIds);
List<CaseMilestone> cmsToUpdate = [select Id, completionDate,MilestoneTypeId,CreatedById,BusinessHoursId,CaseId,ElapsedTimeInDays,ElapsedTimeInHrs,IsCompleted,IsViolated from CaseMilestone cm where caseId in :caseIds /* and cm.MilestoneType.Name=:Milestone2 */ and completionDate != null limit 1];
system.debug('cmsToUpdate :'+cmsToUpdate);
for(CaseMilestone cm :cmsToUpdate)
{
Commision__c com = new Commision__c();
com.Case__c = cm.CaseId;
com.OwnerId =cm.CreatedById;
com.Owner__c=cm.CreatedById;
com.IsCompleted__c=cm.IsCompleted;
com.CompletionDate__c=cm.completionDate;
com.Milestone_Name__c=cm.MilestoneTypeId;
Comlist.add(com);
}
insert Comlist;
system.debug('Comlist :'+Comlist);
}
catch (Exception e){
system.debug('Exeption ::'+e + 'Line Number ::' +e.getLineNumber() + 'getCause ::' +e.getCause()+ 'getMessage ::'+e.getMessage());
}
}
Thanks,
can any one help test class for following trigger
trigger CaseMilestone on Case (after update) {
try{
set <Id> caseIds =new set <Id>();
list<Commision__c> Comlist =new list<Commision__c>();
for(case c:trigger.new)
{
if(c.Status == 'closed' && c.Milestone_Approval_Status__c ==TRUE){
caseIds.add(c.id);
}
}
system.debug('caseIds :'+caseIds);
List<CaseMilestone> cmsToUpdate = [select Id, completionDate,MilestoneTypeId,CreatedById,BusinessHoursId,CaseId,ElapsedTimeInDays,ElapsedTimeInHrs,IsCompleted,IsViolated from CaseMilestone cm where caseId in :caseIds /* and cm.MilestoneType.Name=:Milestone2 */ and completionDate != null limit 1];
system.debug('cmsToUpdate :'+cmsToUpdate);
for(CaseMilestone cm :cmsToUpdate)
{
Commision__c com = new Commision__c();
com.Case__c = cm.CaseId;
com.OwnerId =cm.CreatedById;
com.Owner__c=cm.CreatedById;
com.IsCompleted__c=cm.IsCompleted;
com.CompletionDate__c=cm.completionDate;
com.Milestone_Name__c=cm.MilestoneTypeId;
Comlist.add(com);
}
insert Comlist;
system.debug('Comlist :'+Comlist);
}
catch (Exception e){
system.debug('Exeption ::'+e + 'Line Number ::' +e.getLineNumber() + 'getCause ::' +e.getCause()+ 'getMessage ::'+e.getMessage());
}
}
Thanks,
Try the following code :
Hope this helps!
Please mark this question as Solved if you think your question was answered, so that others could view it as a proper solution.
Thanks,
Apoorv
Beacuse this fallowing part is not covering
List<CaseMilestone> cmsToUpdate = [select Id, completionDate,MilestoneTypeId,CreatedById,BusinessHoursId,CaseId,ElapsedTimeInDays,ElapsedTimeInHrs,IsCompleted,IsViolated from CaseMilestone cm where caseId in :caseIds /* and cm.MilestoneType.Name=:Milestone2 */ and completionDate != null limit 1];
system.debug('cmsToUpdate :'+cmsToUpdate);
for(CaseMilestone cm :cmsToUpdate)
{
Commision__c com = new Commision__c();
com.Case__c = cm.CaseId;
com.OwnerId =cm.CreatedById;
com.Owner__c=cm.CreatedById;
com.IsCompleted__c=cm.IsCompleted;
com.CompletionDate__c=cm.completionDate;
com.Milestone_Name__c=cm.MilestoneTypeId;
Comlist.add(com);
}
insert Comlist;
Thanks,
Hi Mahesh,
You have already got solution for your test class above, here is just a suggestion from my side ono your code to make it a bit better.
With trigger.new list you get all data for those records so you don't need to query it again. you can directly run only one for loop on trigger.new list and as per conditions then process further. here you save one query and one for loop which in turns affects processing time and salesforce query limits when you have multiple triggers or workflows on the same object. Also always have asserts in test methods so that when your functionality grows you get to know what imact of new changes is on existing functionality.
Please see changes below :
Thanks,
Pankaj.