+ Start a Discussion
kiranmutturukiranmutturu 

strange issues on test classes

1. created a test class and inserted an opportunity with stage value as 'started';

2. once the insertion was done changed the stage value to 'in progress' and used update statement to update the same.

3. its entering in to the before trigger event but not firing the class method based on th below condition.

 

test class:

    opprtunity opp = new opportunity(stagename = 'started', name = 'test name');

insert opp;

opp.stagename='in progress';

update opp;

 

if(trigger.new[0].stagename == 'in progress' && trigger.old[0].stagename == 'started')// this is covering.

     hadnler.getoppor(trigger.new[0]);///This is not executing in my scenario

 

 

plez help me out in this

SamuelDeRyckeSamuelDeRycke

Did you chek what the trigger.new[0].stagename and trigger.old[0].stagename values are ?

 

It may help if you post your full trigger & test code.

 

 

kiranmutturukiranmutturu

this is my code in opportunity trigger

if(!OpportunityTriggerHandler_AC.beforeUpdateRecursiveFlag){
OpportunityTriggerHandler_AC.beforeUpdateRecursiveFlag = true;
//Start Code change By Kiran
system.debug('&&&'+trigger.new[0].StageName+'old'+trigger.old[0].stagename);
if(trigger.new[0].RecordTypeid == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(RecordTypeConstants_AC.OPTY_ALLIANCE_AGREEMENT_RT).getRecordTypeId()){
if(trigger.new[0].stagename == '30 - Solution Presentation' && trigger.old[0].StageName == '22 - Proposal Development')

 

test class code:

Account objAct = new Account();
objAct.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get(RecordTypeConstants_AC.ACCOUNT_BUSINESS_ACCOUNT_RT).getRecordTypeId();
objAct.Name = 'test acct';
objAct.Account_Owner_Manager__c = userinfo.getUserId();
//objAct.CCM__c = userinfo.getuserid();
//objAct.Proposal_Manager__c = userinfo.getuserid();
//objAct.Sponsor__c = userinfo.getuserid();
Test.starttest();
insert objAct;
Opportunity objOpp = new Opportunity();
objOpp.AccountId = objAct.id;
objOpp.StageName = '22 - Proposal Development';
objOpp.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get(RecordTypeConstants_AC.OPTY_ALLIANCE_AGREEMENT_RT).getRecordTypeId();
objOpp.Name = 'test opp';
objopp.Class_Type__c = 'Academic Partnership - AMOU';
objOpp.CloseDate = system.today();
objOpp.Type_of_Agreement__c = 'AMOU';
system.debug('stage'+objOpp.StageName);
//Test.startTest();
insert objOpp;

objOpp.stagename = '30 - Solution Presentation';

update objOpp;