You need to sign in to do that
Don't have an account?
soma s 6
why trigger code covergae always shows 0%
hi all
I have written the below after update trigger on task and also test code, my test code run success but code coverage shows zero percentage could please help me
Salesforce - Unlimited Editiontrigger Trigtask on Task(after update)
{
Set<String> accids = new Set<String>();
Set<String> taskaccid= new Set<String>();
Set<String> acountph= new Set<String>();
string taskacno ;
for(task acc: Trigger.new)
{
List<Task> accListS = [select accountid from task where accountid IN :accids AND CallDisposition LIKE '%Lead%'];
if(accListS != null && !accListS .isEmpty())
{
taskacno = acc.accountid;
taskaccid.add(acc.accountid);
}
}
List<Account> accphone = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: taskaccid];
if(accphone != null && !accphone .isEmpty())
{
for(Account accph: accphone )
{
acountph.add(accph.Phone);
}
}
if(!acountph.isEmpty())
{
List<Account> accList = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: acountph]; {
for(Account acc: accList)
{
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID ==taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
//acc.PersonDoNotCall = True;
}
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID !=taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
acc.PersonDoNotCall = True;
}
}
update accList;
}
}
}
test code
Salesforce - Unlimited Edition@isTest
public class Tritasktest{
static testMethod void testMethodOne()
{
Account accone = new Account();
accone .Name='Test Account Two';
accone .Phone='555555';
accone .StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accone ;
Task taskone= new task();
taskone.whatid= accone .id;
taskone.CallDisposition ='Leadrep';
// taskone.what=accTwo.id;
insert taskone;
Account acctwo = new Account();
accTwo.Name='Test Account Two';
acctwo.Phone='555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accTwo;
Task tasktwo= new task();
tasktwo.whatid= acctwo .id;
tasktwo.CallDisposition ='Leadrep';
// taskone.what=accTwo.id;
insert tasktwo;
task acc = [select Id,accountid, CallDisposition,Account_Ph_No__c from task where whatId =: accone.Id LIMIT 1];
// Account acc = [select Id, StrPhr_Do_Not_Call_Group_Practice__c from Account where Id =: accTwo.Id LIMIT 1];
//system.assertequals([select Account_Ph_No__c from task where whatId =:accone.Id],'555555');
System.assertEquals(acc.accountid,accone.id );
//System.assertEquals(acc.name, ‘testName’);
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = true;
update accTwo;
//List<Task> accListS = [select accountid from task where accountid IN :accids AND CallDisposition LIKE '%Lead%'];
}
static testMethod void testMethodTwo()
{
Account accOne = new Account();
accOne.Name='Test Account One';
accOne.StrPhr_Do_Not_Call_Group_Practice__c = false;
accOne.Phone ='5555555555';
insert accOne;
Account accTwo = new Account();
accTwo.Name='Test Account Two';
accTwo.StrPhr_Lead_Qualified__c = false;
accTwo.Phone ='5555555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
accTwo.PersonDoNotCall = false;
insert accTwo;
accTwo.StrPhr_Lead_Qualified__c = True;
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = True;
//accTwo.PersonDoNotCall = True;
update accTwo;
}
}
I have written the below after update trigger on task and also test code, my test code run success but code coverage shows zero percentage could please help me
Salesforce - Unlimited Editiontrigger Trigtask on Task(after update)
{
Set<String> accids = new Set<String>();
Set<String> taskaccid= new Set<String>();
Set<String> acountph= new Set<String>();
string taskacno ;
for(task acc: Trigger.new)
{
List<Task> accListS = [select accountid from task where accountid IN :accids AND CallDisposition LIKE '%Lead%'];
if(accListS != null && !accListS .isEmpty())
{
taskacno = acc.accountid;
taskaccid.add(acc.accountid);
}
}
List<Account> accphone = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: taskaccid];
if(accphone != null && !accphone .isEmpty())
{
for(Account accph: accphone )
{
acountph.add(accph.Phone);
}
}
if(!acountph.isEmpty())
{
List<Account> accList = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: acountph]; {
for(Account acc: accList)
{
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID ==taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
//acc.PersonDoNotCall = True;
}
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID !=taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
acc.PersonDoNotCall = True;
}
}
update accList;
}
}
}
test code
Salesforce - Unlimited Edition@isTest
public class Tritasktest{
static testMethod void testMethodOne()
{
Account accone = new Account();
accone .Name='Test Account Two';
accone .Phone='555555';
accone .StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accone ;
Task taskone= new task();
taskone.whatid= accone .id;
taskone.CallDisposition ='Leadrep';
// taskone.what=accTwo.id;
insert taskone;
Account acctwo = new Account();
accTwo.Name='Test Account Two';
acctwo.Phone='555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accTwo;
Task tasktwo= new task();
tasktwo.whatid= acctwo .id;
tasktwo.CallDisposition ='Leadrep';
// taskone.what=accTwo.id;
insert tasktwo;
task acc = [select Id,accountid, CallDisposition,Account_Ph_No__c from task where whatId =: accone.Id LIMIT 1];
// Account acc = [select Id, StrPhr_Do_Not_Call_Group_Practice__c from Account where Id =: accTwo.Id LIMIT 1];
//system.assertequals([select Account_Ph_No__c from task where whatId =:accone.Id],'555555');
System.assertEquals(acc.accountid,accone.id );
//System.assertEquals(acc.name, ‘testName’);
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = true;
update accTwo;
//List<Task> accListS = [select accountid from task where accountid IN :accids AND CallDisposition LIKE '%Lead%'];
}
static testMethod void testMethodTwo()
{
Account accOne = new Account();
accOne.Name='Test Account One';
accOne.StrPhr_Do_Not_Call_Group_Practice__c = false;
accOne.Phone ='5555555555';
insert accOne;
Account accTwo = new Account();
accTwo.Name='Test Account Two';
accTwo.StrPhr_Lead_Qualified__c = false;
accTwo.Phone ='5555555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
accTwo.PersonDoNotCall = false;
insert accTwo;
accTwo.StrPhr_Lead_Qualified__c = True;
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = True;
//accTwo.PersonDoNotCall = True;
update accTwo;
}
}
Salesforce - Unlimited Editiontrigger Trigtask on Task(after update)
{
Set<String> accids = new Set<String>();
Set<String> taskaccid= new Set<String>();
Set<String> acountph= new Set<String>();
string taskacno ;
for(task acc: Trigger.new)
{
List<Task> accListS = [select accountid from task where accountid IN :accids AND CallDisposition LIKE '%Lead%'];
if(accListS != null && !accListS .isEmpty())
{
taskacno = acc.whatid;
taskaccid.add(acc.whatid);
}
}
List<Account> accphone = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: taskaccid];
if(accphone != null && !accphone .isEmpty())
{
for(Account accph: accphone )
{
acountph.add(accph.Phone);
}
}
if(!acountph.isEmpty())
{
List<Account> accList = [Select Id,IsPersonAccount,StrPhr_Do_Not_Call_Group_Practice__c, PersonDoNotCall,StrPhr_Lead_Qualified__c from Account where Phone IN: acountph]; {
for(Account acc: accList)
{
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID ==taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
//acc.PersonDoNotCall = True;
}
if ( acc.IsPersonAccount == true && acc.StrPhr_Do_Not_Call_Group_Practice__c == False && acc.ID !=taskacno )
{
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
acc.PersonDoNotCall = True;
}
}
update accList;
}
}
}
test code
@isTest
public class Tritasktest{
static testMethod void testMethodOne()
{
Account accone = new Account();
accone .Name='Test Account Two';
accone .Phone='555555';
accone .StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accone ;
accone .Phone='555555';
accone .StrPhr_Do_Not_Call_Group_Practice__c = true;
update accone ;
Task taskone= new task();
taskone.whatid= accone .id;
taskone.CallDisposition ='Leadrep';
insert taskone;
Account acctwo = new Account();
accTwo.Name='Test Account Two';
acctwo.Phone='555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
insert accTwo;
acctwo.Phone='555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = true;
update accTwo;
Task tasktwo= new task();
tasktwo.whatid= acctwo .id;
tasktwo.CallDisposition ='Leadrep';
insert tasktwo;
tasktwo.whatid= acctwo.id;
Task t=[SELECT whatid,CallDisposition FROM Task WHERE whatid=:acctwo.id].get(0);
tasktwo.CallDisposition='Lead';
update tasktwo;
Account acc1 = [select Id,isPersonAccount, StrPhr_Do_Not_Call_Group_Practice__c,phone from Account where Id =: accTwo.Id LIMIT 1];
System.assertEquals(true, acc1.StrPhr_Do_Not_Call_Group_Practice__c);
System.assertEquals('555555', acc1.Phone);
task acc = [select Id,whatid,accountid, CallDisposition,Account_Ph_No__c from task where whatId =: accone.Id LIMIT 1];
System.assertEquals(acc.whatid,accone.id );
}
static testMethod void testMethodTwo()
{
Account accOne = new Account();
accOne.Name='Test Account One';
accOne.StrPhr_Do_Not_Call_Group_Practice__c = false;
accOne.Phone ='5555555555';
insert accOne;
Account accTwo = new Account();
accTwo.Name='Test Account Two';
accTwo.StrPhr_Lead_Qualified__c = false;
accTwo.Phone ='5555555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = false;
accTwo.PersonDoNotCall = false;
insert accTwo;
accTwo.StrPhr_Lead_Qualified__c = True;
accTwo.Phone ='5555555555';
accTwo.StrPhr_Do_Not_Call_Group_Practice__c = True;
update accTwo;
}
}
taskacno = acc.whatid;
taskaccid.add(acc.whatid);
for(Accounfor(Account accph: accphone )
{
acountph.add(accph.Phone)
if(!acountph.isEmpty()
acc.StrPhr_Do_Not_Call_Group_Practice__c=True;
already in my test class am inserting task.calldisposition ='Leadrep'