You need to sign in to do that
Don't have an account?
Kon Dele
Test Coverage only 50%
Trying to get at least 75% coverage on this trigger. Here's what i have so far
My trigger:
trigger UpdateOpptyPicklists on Opportunity(Before Insert, Before Update) {
for(Opportunity o: Trigger.new){
Account a = [select id,LC_Region__c,LC_Area__c, LC_Division__c from Account where Id=:o.AccountId];
if(o.LC_Region__c == NULL || o.LC_Area__c == NULL || o.LC_Division__c == NULL){
o.LC_Region__c=a.LC_Region__c;
o.LC_Area__c = a.LC_Area__c;
o.LC_Division__c=a.LC_Division__c;
}
}
}
The test class:
@isTest
private class UnitTests_UpdateOpptyPicklists {
static testMethod void myUnitTest() {
Account a = new Account();
a.Name='TEST ACCOUNT';
a.Type='Competitor';
a.LC_Region__c='Americas';
a.LC_Area__c='West';
a.LC_Division__c='MA';
insert a;
Opportunity o=new Opportunity();
o.Name='TEST';
o.AccountId=a.Id;
o.Type='New Customer';
o.closeDate=date.today();
o.StageName='Prospecting';
o.Amount=10000;
o.LC_Region__c='Americas';
o.LC_Area__c='East';
o.LC_Division__c='SE';
insert o;
RecordType rt=new RecordType();
try{
rt=[SELECT Id from RecordType where sObjectType='Opportunity' and isActive=true limit 1];
}
catch(Exception e){
rt=null;
}
if(o.LC_Region__c == NULL || o.LC_Area__c == NULL || o.LC_Division__c == NULL){
o.LC_Region__c=a.LC_Region__c;
o.LC_Area__c=a.LC_Region__c;
o.LC_Division__c=a.LC_Region__c;
update o;
}
}
}
Could someone enlighten me why I'm I getting only 50% coverage
My trigger:
trigger UpdateOpptyPicklists on Opportunity(Before Insert, Before Update) {
for(Opportunity o: Trigger.new){
Account a = [select id,LC_Region__c,LC_Area__c, LC_Division__c from Account where Id=:o.AccountId];
if(o.LC_Region__c == NULL || o.LC_Area__c == NULL || o.LC_Division__c == NULL){
o.LC_Region__c=a.LC_Region__c;
o.LC_Area__c = a.LC_Area__c;
o.LC_Division__c=a.LC_Division__c;
}
}
}
The test class:
@isTest
private class UnitTests_UpdateOpptyPicklists {
static testMethod void myUnitTest() {
Account a = new Account();
a.Name='TEST ACCOUNT';
a.Type='Competitor';
a.LC_Region__c='Americas';
a.LC_Area__c='West';
a.LC_Division__c='MA';
insert a;
Opportunity o=new Opportunity();
o.Name='TEST';
o.AccountId=a.Id;
o.Type='New Customer';
o.closeDate=date.today();
o.StageName='Prospecting';
o.Amount=10000;
o.LC_Region__c='Americas';
o.LC_Area__c='East';
o.LC_Division__c='SE';
insert o;
RecordType rt=new RecordType();
try{
rt=[SELECT Id from RecordType where sObjectType='Opportunity' and isActive=true limit 1];
}
catch(Exception e){
rt=null;
}
if(o.LC_Region__c == NULL || o.LC_Area__c == NULL || o.LC_Division__c == NULL){
o.LC_Region__c=a.LC_Region__c;
o.LC_Area__c=a.LC_Region__c;
o.LC_Division__c=a.LC_Region__c;
update o;
}
}
}
Could someone enlighten me why I'm I getting only 50% coverage
2.) As why 50% code is covered,the reason is that you are not satisfying your if condition.Try below code : If this helps,please mark it as best answer to help others :)
All Answers
2.) As why 50% code is covered,the reason is that you are not satisfying your if condition.Try below code : If this helps,please mark it as best answer to help others :)
Thanks Again!