触发器测试 class 的测试覆盖率不断显示 53
Test coverage for test class of trigger is showing 53 constantly
我是 salesforce 的新手 development.I 已经编写了以下触发器的测试 class,它的覆盖率仅为 53。我通过在测试 class 中添加和更改代码行进行了多次尝试,但它仍然显示 53。你能帮我解决这个问题吗?
提前致谢。任何帮助将不胜感激。
trigger CaseTrigger on Case (before insert,before update, after update)
{
if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
{
List<Id> contactIds = new List<Id>();
List<Id> acctIds = new List<Id>();
for (Case c: Trigger.new){
if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
contactIds.add(c.ContactId);
acctIds.add(c.AccountId);
}
}
if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
/* Added check for active entitlement */
List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
Where e.ContactId in:contactIds
And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
if(entlContacts.isEmpty()==false){
for(Case c: Trigger.new){
if(c.EntitlementId == null && c.ContactId!= null){
for(EntitlementContact ec:entlContacts){
if(ec.ContactId==c.ContactId){
c.EntitlementId = ec.EntitlementId;
if(c.AssetId==null && ec.Entitlement.AssetId!=null)
c.AssetId=ec.Entitlement.AssetId;
break;
}
} // end for entitlement
}
} // end for case
} else{
List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
From Entitlement e
Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
if(entls.isEmpty()==false){
for(Case c: Trigger.new){
if(c.EntitlementId == null && c.AccountId!= null){
for(Entitlement e:entls){
if(e.AccountId==c.AccountId){
c.EntitlementId = e.Id;
if(c.AssetId==null && e.AssetId!=null)
c.AssetId=e.AssetId;
break;
}
} // end for
}
} // end for
}
}
} // end if(contactIds.isEmpty()==false)
}
if(Trigger.isBefore && Trigger.isUpdate)
{
System.debug('entered if condition');
for(Case c : Trigger.new)
{
if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
System.debug('Updating logic');
List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
for(Group g : qid)
{
c.OwnerId = g.id;
System.debug('updated');
}
}}
}
if(Trigger.isBefore && Trigger.isUpdate)
{
for(Case c : Trigger.new)
{
if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
{
c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com';
}
}
}
if(Trigger.isBefore && Trigger.isUpdate)
{
for(Case c : Trigger.new)
{
if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low')
{
c.Priority='Planning';
}
if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High')
{
c.Priority='Critical';
}
if(c.Status=='Pending User' || c.Status=='Pending Vendor')
{
c.IsStopped = True;
}
}
}
if((Trigger.isAfter && Trigger.isUpdate))
{
Set<Id> Ids = new Set<Id>();
Set<Id> IdR = new Set<Id>();
Set<Id> IdC = new Set<Id>();
List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>();
List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>();
List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>();
for (Case cs: Trigger.new)
{
Case oldLead = Trigger.oldMap.get(cs.Id);
if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing')
{
Ids.add(cs.Id);
}
if (cs.Status == 'ReOpen')
{
IdR.add(cs.Id);
}
if (cs.Status == 'Closed')
{
IdC.add(cs.Id);
}
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids])
{
if (rateSheet.Status__c != 'Tested') {
rateSheet.Status__c = 'Tested';
//rateSheet.Case__c.Status= 'Awaiting Deployment';
scprblm.add(rateSheet);
}
}
if (!scprblm.isEmpty()) {
update scprblm;
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR])
{
// List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old];
if (rateSheet.Status__c != 'Open') {
rateSheet.Status__c = 'Open';
scprblmo.add(rateSheet);
}
}
if (!scprblmo.isEmpty()) {
update scprblmo;
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC])
{
if (rateSheet.Status__c != 'Closed') {
rateSheet.Status__c = 'Closed';
scprblmc.add(rateSheet);
}
}
if (!scprblmc.isEmpty()) {
update scprblmc;
}
}
}
您好 SAdmin,欢迎来到社区。
您可以使用 Developer Console 来检查您的代码的哪一部分未包含在您的测试中 class。每次你 运行 你的测试 class 你都可以通过单击主顶点 class 上的 Code Coverage
下拉菜单来查看覆盖了哪些代码行。
这样你可以看到被测试覆盖的代码行是蓝色的。未覆盖的代码行是红色的。不需要覆盖的代码行(例如,大括号、注释和 System.debug 调用)保留为白色。
请查看 this 指南以了解更多信息。
我是 salesforce 的新手 development.I 已经编写了以下触发器的测试 class,它的覆盖率仅为 53。我通过在测试 class 中添加和更改代码行进行了多次尝试,但它仍然显示 53。你能帮我解决这个问题吗?
提前致谢。任何帮助将不胜感激。
trigger CaseTrigger on Case (before insert,before update, after update)
{
if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
{
List<Id> contactIds = new List<Id>();
List<Id> acctIds = new List<Id>();
for (Case c: Trigger.new){
if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
contactIds.add(c.ContactId);
acctIds.add(c.AccountId);
}
}
if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
/* Added check for active entitlement */
List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
Where e.ContactId in:contactIds
And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
if(entlContacts.isEmpty()==false){
for(Case c: Trigger.new){
if(c.EntitlementId == null && c.ContactId!= null){
for(EntitlementContact ec:entlContacts){
if(ec.ContactId==c.ContactId){
c.EntitlementId = ec.EntitlementId;
if(c.AssetId==null && ec.Entitlement.AssetId!=null)
c.AssetId=ec.Entitlement.AssetId;
break;
}
} // end for entitlement
}
} // end for case
} else{
List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
From Entitlement e
Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
if(entls.isEmpty()==false){
for(Case c: Trigger.new){
if(c.EntitlementId == null && c.AccountId!= null){
for(Entitlement e:entls){
if(e.AccountId==c.AccountId){
c.EntitlementId = e.Id;
if(c.AssetId==null && e.AssetId!=null)
c.AssetId=e.AssetId;
break;
}
} // end for
}
} // end for
}
}
} // end if(contactIds.isEmpty()==false)
}
if(Trigger.isBefore && Trigger.isUpdate)
{
System.debug('entered if condition');
for(Case c : Trigger.new)
{
if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
System.debug('Updating logic');
List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
for(Group g : qid)
{
c.OwnerId = g.id;
System.debug('updated');
}
}}
}
if(Trigger.isBefore && Trigger.isUpdate)
{
for(Case c : Trigger.new)
{
if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
{
c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com';
}
}
}
if(Trigger.isBefore && Trigger.isUpdate)
{
for(Case c : Trigger.new)
{
if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low')
{
c.Priority='Planning';
}
if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High')
{
c.Priority='Critical';
}
if(c.Status=='Pending User' || c.Status=='Pending Vendor')
{
c.IsStopped = True;
}
}
}
if((Trigger.isAfter && Trigger.isUpdate))
{
Set<Id> Ids = new Set<Id>();
Set<Id> IdR = new Set<Id>();
Set<Id> IdC = new Set<Id>();
List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>();
List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>();
List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>();
for (Case cs: Trigger.new)
{
Case oldLead = Trigger.oldMap.get(cs.Id);
if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing')
{
Ids.add(cs.Id);
}
if (cs.Status == 'ReOpen')
{
IdR.add(cs.Id);
}
if (cs.Status == 'Closed')
{
IdC.add(cs.Id);
}
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids])
{
if (rateSheet.Status__c != 'Tested') {
rateSheet.Status__c = 'Tested';
//rateSheet.Case__c.Status= 'Awaiting Deployment';
scprblm.add(rateSheet);
}
}
if (!scprblm.isEmpty()) {
update scprblm;
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR])
{
// List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old];
if (rateSheet.Status__c != 'Open') {
rateSheet.Status__c = 'Open';
scprblmo.add(rateSheet);
}
}
if (!scprblmo.isEmpty()) {
update scprblmo;
}
for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC])
{
if (rateSheet.Status__c != 'Closed') {
rateSheet.Status__c = 'Closed';
scprblmc.add(rateSheet);
}
}
if (!scprblmc.isEmpty()) {
update scprblmc;
}
}
}
您好 SAdmin,欢迎来到社区。
您可以使用 Developer Console 来检查您的代码的哪一部分未包含在您的测试中 class。每次你 运行 你的测试 class 你都可以通过单击主顶点 class 上的 Code Coverage
下拉菜单来查看覆盖了哪些代码行。
这样你可以看到被测试覆盖的代码行是蓝色的。未覆盖的代码行是红色的。不需要覆盖的代码行(例如,大括号、注释和 System.debug 调用)保留为白色。
请查看 this 指南以了解更多信息。