+ Start a Discussion
DivyaReddyDivyaReddy 

Help on test case ..

Can any one sugesst me to cover this part

 

 Else If(Trigger.IsUpdate)
        {
            String ProfileName = [SELECT Profile.Name FROM User where Id = :Trigger.New[0].OwnerId].Profile.Name;    
            If(Trigger.New[0].OwnerId != Trigger.Old[0].OwnerId)
            {
                
                
                If(ProfileName.contains('Sales'))
                {
                    Trigger.New[0].Sales_Consultant__c = Trigger.New[0].OwnerId;
                    
                    If(Trigger.New[0].Sales_Consultant__c != null)
                    {
                    Trigger.New[0].Sales_Consultan__c = Trigger.New[0].OwnerId;
                    }

                }
                if(ProfileName.contains('Process'))
                 {
                    Trigger.New[0].Process_Consultant__c = Trigger.New[0].OwnerId;
                    
                    If(Trigger.New[0].Process_Consultant__c != null)
                    {
                    Trigger.New[0].Process_Consultant_User__c = Trigger.New[0].OwnerId;
                    }
                 }
                 
            }

ashish raiashish rai

Hello,

      To cover the update part you have to update the opportunity but makesure that you have to update the opportunity ownerid with different user id.For example;

 @isTest
private class trgCaptureConsultants_TESTS

{

static testMethod void mytestclass()

   {

       Profile p = [select id from profile where name='Custom: Sales Profile'];
        User u1 = new User(alias = 'standt2', email='standarduser@test12.com',
        emailencodingkey='UTF-8', lastname='Testing1', languagelocalekey='en_US',
        localesidkey='en_US', profileid = p.Id,firstname='Heather',
        timezonesidkey='America/Los_Angeles', username='standarduser@test12.com');
        insert u1; 

        Insert u2;

        Opportunity o = new Opportunity();

        o.name = 'raja';

        o.ownerId=u1.id;
        o.Accountid = a.id;
        o.StageName = 'Opened';
       o.CloseDate = system.today();
       o.Process_Consultant__c = '0053000000203VvAAI';
       o.Sales_Consultan__c = null ;
       o.StageName = 'Evaluation Sale Made';
       o.Apply_For_Exception_Withdrawal_Refund__c = False ;
       insert o;

       o.ownerId=u2.id;

       update o;

}

}

 

This will help you to over the update part.Now update the same at all insert position but after insert write this..