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', ProfileId=p1.id, UserCd_TermServ_Acct__c='1234', EmailEncodingKey='ISO-8859-1',LanguageLocaleKey='en_US',TimeZoneSidKey='America/Los_Angeles', LocaleSidKey='en_US'); insert u; User u1 = new user(Firstname = 'testfn1', Lastname= 'testln1', Alias = 'ttest1', email = 'hrmssoft1@gmail.com', username = 'hrms1@yahoo.com', UserCd_TermServ_Acct__c='12345', ProfileId=[select id,name from Profile where Name=' Manager'].id, EmailEncodingKey='ISO-8859-1',LanguageLocaleKey='en_US',TimeZoneSidKey='America/Los_Angeles', LocaleSidKey='en_US'); insert u1; system.runAs(u){ 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'; c.MailingState='NC'; c.MailingPostalCode='27517'; insert c;
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
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',
ProfileId=p1.id,
UserCd_TermServ_Acct__c='1234',
EmailEncodingKey='ISO-8859-1',LanguageLocaleKey='en_US',TimeZoneSidKey='America/Los_Angeles',
LocaleSidKey='en_US');
insert u;
User u1 = new user(Firstname = 'testfn1',
Lastname= 'testln1',
Alias = 'ttest1',
email = 'hrmssoft1@gmail.com',
username = 'hrms1@yahoo.com',
UserCd_TermServ_Acct__c='12345',
ProfileId=[select id,name from Profile where Name=' Manager'].id,
EmailEncodingKey='ISO-8859-1',LanguageLocaleKey='en_US',TimeZoneSidKey='America/Los_Angeles',
LocaleSidKey='en_US');
insert u1;
system.runAs(u){
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';
c.MailingState='NC';
c.MailingPostalCode='27517';
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];
System.runAs(u1){
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>();
ops.add(op);
Database.SaveResult[] srList = Database.update(ops, false);
system.debug(' op owner : '+op.OwnerId);
}
}
}
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.
Thanks.
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