You need to sign in to do that
Don't have an account?
sam_Admin
Apex test class coverage
Can someone help with me test class coverage? iam only getting 63%
Trigger:
trigger OppDemoDate on CSActivity__c (before insert, before update)
{
Opportunity opt = new Opportunity();
opt = [select Id,Demo_Date__c from Opportunity where id =:trigger.new[0].OpportunityName__c];
list<CSActivity__c> cslist = [Select c.Start_Date_Time__c, c.OpportunityName__c, c.Id, c.CreatedDate, c.ActivityType__c From CSActivity__c c where c.OpportunityName__c =: opt.id and c.ActivityType__c=:'Demo' order by c.CreatedDate limit 1];
if(cslist.size()>0)
{
if(trigger.new[0].Id == cslist[0].Id){
opt.Demo_Date__c = trigger.new[0].Start_Date_Time__c;
update opt;
}
}
else{
if(trigger.new[0].ActivityType__c == 'Demo'){
opt.Demo_Date__c = trigger.new[0].Start_Date_Time__c;
if(!Test.isRunningTest()){
update opt;
}
}
}
}
Test Class:
@isTest
private class OppDemoDate_test {
static testMethod void myUnitTest() {
// TO DO: implement unit test
Account acc = new Account(Name = 'test', phone = '1234567890');
insert acc;
Opportunity opp = new Opportunity(SaleType__c = 'new', Name = 'test', AccountId = acc.Id ,
Amount = 50, CurrencyIsoCode = 'USD', CloseDate = Date.newInstance(2009,02,01), StageName = 'Closed',
ForecastCategoryName = 'omitted', Probability_SonoWin__c = '10', Probability_Any_Order__c = '20', SystemType__c = 'Other',
SystemQty__c = 0, Demo_Date__c = Date.newInstance(2019,02,01) );
insert opp;
CSActivity__c ccr = new CSActivity__c(Name = 'Test', ActivityType__c = 'Demo', Clinical_Support_Type__c = 'Test', Start_Date_Time__c = Date.newInstance(2009,02,01), Start_Time__c = '0', End_Time__c = '1', Sales_Region__c = 'Test', OpportunityName__c = opp.Id);
insert ccr;
}
}
Trigger:
trigger OppDemoDate on CSActivity__c (before insert, before update)
{
Opportunity opt = new Opportunity();
opt = [select Id,Demo_Date__c from Opportunity where id =:trigger.new[0].OpportunityName__c];
list<CSActivity__c> cslist = [Select c.Start_Date_Time__c, c.OpportunityName__c, c.Id, c.CreatedDate, c.ActivityType__c From CSActivity__c c where c.OpportunityName__c =: opt.id and c.ActivityType__c=:'Demo' order by c.CreatedDate limit 1];
if(cslist.size()>0)
{
if(trigger.new[0].Id == cslist[0].Id){
opt.Demo_Date__c = trigger.new[0].Start_Date_Time__c;
update opt;
}
}
else{
if(trigger.new[0].ActivityType__c == 'Demo'){
opt.Demo_Date__c = trigger.new[0].Start_Date_Time__c;
if(!Test.isRunningTest()){
update opt;
}
}
}
}
Test Class:
@isTest
private class OppDemoDate_test {
static testMethod void myUnitTest() {
// TO DO: implement unit test
Account acc = new Account(Name = 'test', phone = '1234567890');
insert acc;
Opportunity opp = new Opportunity(SaleType__c = 'new', Name = 'test', AccountId = acc.Id ,
Amount = 50, CurrencyIsoCode = 'USD', CloseDate = Date.newInstance(2009,02,01), StageName = 'Closed',
ForecastCategoryName = 'omitted', Probability_SonoWin__c = '10', Probability_Any_Order__c = '20', SystemType__c = 'Other',
SystemQty__c = 0, Demo_Date__c = Date.newInstance(2019,02,01) );
insert opp;
CSActivity__c ccr = new CSActivity__c(Name = 'Test', ActivityType__c = 'Demo', Clinical_Support_Type__c = 'Test', Start_Date_Time__c = Date.newInstance(2009,02,01), Start_Time__c = '0', End_Time__c = '1', Sales_Region__c = 'Test', OpportunityName__c = opp.Id);
insert ccr;
}
}
Stevee Evans
The best use of myprepaidcenter card (https://myprepaidcenters.co/) to pay your dues and bills at online and offline shops and merchants.