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

Test Case for trigger on task
Hi All,
Can someone help me with test case for this trigger.
trigger UpdateQuoteStatus on task (after insert, after update){
Set<Id> QuoteId = new Set<Id>();
List<Quote> Quotes = new List<Quote>();
for(task t:trigger.new){
if((t.WhatId != NULL && t.WhatId.getSobjectType() == Quote.sobjecttype) && (t.subject.substring(0,5) == 'Email')){
QuoteId.add(t.whatId);
}
}
for(Quote QList:[select Status from Quote where Id IN : QuoteId]){
Quote Qt = new Quote();
Qt.Id = QList.Id;
QList.Status = 'Presented';
Quotes.add(QList);
}
if(Quotes.size()>0){
update Quotes;
}
}
Thanks!
Can someone help me with test case for this trigger.
trigger UpdateQuoteStatus on task (after insert, after update){
Set<Id> QuoteId = new Set<Id>();
List<Quote> Quotes = new List<Quote>();
for(task t:trigger.new){
if((t.WhatId != NULL && t.WhatId.getSobjectType() == Quote.sobjecttype) && (t.subject.substring(0,5) == 'Email')){
QuoteId.add(t.whatId);
}
}
for(Quote QList:[select Status from Quote where Id IN : QuoteId]){
Quote Qt = new Quote();
Qt.Id = QList.Id;
QList.Status = 'Presented';
Quotes.add(QList);
}
if(Quotes.size()>0){
update Quotes;
}
}
Thanks!
Try below code and let me know if you face any issues:
@isTest
Public class Test_taskCoverage{
static testMethod void test_task(){
system.test.startTest();
createTestData();
system.test.stopTest();
}
private static void createTestData(){
Opportunity op = new Opportunity();
op.name = 'test opportunity';
op.stageName = 'prospect';
insert op;
Quote q = new Quote();
q.name = 'test quote';
q.status = 'In Review';
q.opportunityId = op.id;
insert q;
Task t = new Task();
t.whatId = q.id;
t.subject = 'Email';
t.Priority = 'low';
t.status = 'not started';
insert t;
}
}
All Answers
Try below code and let me know if you face any issues:
@isTest
Public class Test_taskCoverage{
static testMethod void test_task(){
system.test.startTest();
createTestData();
system.test.stopTest();
}
private static void createTestData(){
Opportunity op = new Opportunity();
op.name = 'test opportunity';
op.stageName = 'prospect';
insert op;
Quote q = new Quote();
q.name = 'test quote';
q.status = 'In Review';
q.opportunityId = op.id;
insert q;
Task t = new Task();
t.whatId = q.id;
t.subject = 'Email';
t.Priority = 'low';
t.status = 'not started';
insert t;
}
}
Opty Close date is required field which is missed out. Otherwise its working fine. Thanks!!