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

unable to cover the code in testcase, after passing values even
for(Task T1:trigger.new)
{
try{
for(opportunity o:Oppids)
{
if(T1.WhatId == o.id && (T1.Subject).startsWith('Email: BAS') ){
if(o.StageName =='Booking Acknowledged'){
o.BAS_Sent_Date__c=date.valueof(T1.CreatedDate);
o.StageName='Booking Verified';
}}
}
}catch(Exception e){system.debug('Exception Here'+e);}
Could you post the full code, and the test method you are using? That would make it easier to help.
Based on what you posted there, it looks like whatever data you are passing in doesnt meet your first line of logic:
if(T1.WhatId == o.id && (T1.Subject).startsWith('Email: BAS') ){
Are you definitely creating both an opportunity, and a task (which relates to the opportunity) in your testmethod? Does the task you create definitely have a subject set to meet the criteria? (starts with 'Email: BAS')
trigger Update_Opp_BASSENT on Task (after insert) {
public integer count;
Set<ID> Task_whatids=new Set<ID>();
for(Task T1:trigger.new)
{
Task_whatids.add(T1.WhatId );
}
system.debug('taskid'+Task_whatids);
opportunity []Oppids=[select id,BAS_Sent_Date__c,StageName from opportunity where id in:Task_whatids and RecordType.name='Group Sales KZ'];
for(Task T1:trigger.new)
{
try{
for(opportunity o:Oppids)
{
if(T1.WhatId == o.id && (T1.Subject).startsWith('Email: BAS') ){
if(o.StageName =='Booking Acknowledged'){
o.BAS_Sent_Date__c=date.valueof(T1.CreatedDate);
o.StageName='Booking Verified';
}}
}
}catch(Exception e){system.debug('Exception Here'+e);}
}
update oppids;
}
testcase
@isTest
private class Update_Opp_BASSENT_TC{
/**
* @description : Initialization of Objects and methods used in the Class
*/
static testmethod void Test(){
test.starttest();
/*
Account_Running_Number__c ar= new Account_Running_Number__c();
ar.Running_Number__c='1';
ar.Type__c='school';
insert ar;
Account cus1 = new Account();
cus1.LastName = 'asdasd';
cus1.phone='7522455';
cus1.ParentId=NULL;
cus1.Type1__c='school';
cus1.Business_Registration_Number__c='dddee';
cus1.BillingCountry='malaysia';
cus1.BillingState='Johor';
insert cus1;
*/
Opportunity opp = new Opportunity();
opp.Name = 'test';
opp.StageName = 'Needs Analysis';
Opp.closedate = date.ValueOf('2009-09-21');
opp.StageName='Booking Verified';
insert opp;
contact c= new contact();
c.lastname='teeet';
insert c;
Task t = new Task();
t.subject = ' Email: BASaaaa';
t.WhatId= opp.id;
t.status = 'open';
t.description = 'ddd';
insert t;
Task t1= new Task();
t1.subject = ' BASaaa';
t1.WhatId= opp.id;
t1.status = 'open';
t1.description = 'ddd';
insert t1;
test.stoptest();
}
}