+ Start a Discussion
vamshi kothakapu 9vamshi kothakapu 9 

Trigger test class not taking old and new values

User-added imageNot able to pass the if condition of old and new values compariosn.
Im updating record ownerid from test class but still ownerId in,logs is same
vamshi kothakapu 9vamshi kothakapu 9
Above if condition Im pringting Ownerid, they are coming out as same.
Plz help me -- Here is my test method which has issue:
static testMethod void Unittest () {
        //Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
        Profile p1=[SELECT Id From Profile WHERE Name=' Manager'];
        User u = new user(Firstname = 'testfn', 
                          Lastname= 'testln',
                          Alias = 'ttest',
                          email = 'hrmssoft@gmail.com',
                          username = 'hrms@yahoo.com',
        insert u;
          User u1 = new user(Firstname = 'testfn1', 
                           Lastname= 'testln1',
                           Alias = 'ttest1',
                           email = 'hrmssoft1@gmail.com',
                           username = 'hrms1@yahoo.com',
                           ProfileId=[select id,name from Profile where Name=' Manager'].id,
        insert u1;
            Account acc = new Account();
            acc.Name = 'Old Parent Account';
            acc.BillingStreet = '123 Easy Street';
            acc.BillingCity = 'Chapel Hill';
            acc.BillingState = 'NC';
            acc.BillingPostalCode = '27517';
            acc.Account_Number__c = 500;
            insert acc;
            contact c = new contact();
            c.lastname = 'test';
            c.MailingStreet='123 Easy Street';
            c.MailingCity='Chapel Hill';
            insert c;
            Commission_User__c cuser = new Commission_User__c();
            cuser.First_Name__c ='Unitfirstname';
            cuser.Last_Name__c ='Lastname';
            cuser.Employee_ID__c ='Employeeid';
            cuser.Active__c = true;
            insert cuser;
            Opportunity op = new Opportunity();
            op.Name = 'Test Opportunity';
            op.StageName = 'In Progress';
            op.CloseDate = Date.today();
            op.Type = 'Add-On';
            op.OwnerId = u.id;
            op.AccountId = acc.Id;
            insert op;
            system.debug(' op owner : '+op.OwnerId);
        //Opportunity op = [select id,name from Opportunity where name='Test Opportunity' limit 1];
            Commission_User__c cuser1 = new Commission_User__c();
            cuser1.First_Name__c ='Unitfirstname1';
            cuser1.Last_Name__c ='Lastname1';
            cuser1.Employee_ID__c ='Employeeid1';
            cuser1.Active__c = true;
            insert cuser1;
            op.OwnerId = u1.id;
            update op;
            list<opportunity> ops = new  list<opportunity>();
            Database.SaveResult[] srList = Database.update(ops, false);
            system.debug(' op owner : '+op.OwnerId);
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vamshi,

In the test data, you are inserting the record fields are they correct so that the if condition evaluates to true.

If not please try to set the fields so that the conditional blocks are satisfied and the code is covered.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

vamshi kothakapu 9vamshi kothakapu 9
   if(op.OwnerId != opportunitiesMap.get(op.id).ownerId )
      new ownerID != Old.ownerId
For above condition Iam inserting record OwnerId with a user and updating the  OwnerId  as another user but still its showing as same user id in logs