You need to sign in to do that
Don't have an account?

Why is this test failing
Here is the Apex Class
Here is the test class
The test class fails as shown below
As you can see the debug log shows the lead OwnerId has changed but the change does not persist outside the class in the test. What am I missing?
public class AssignLeadsUsingAssignmentRules { @InvocableMethod public static void LeadAssign(List<Id> LeadIds) { Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true; Lead Leads=[select id,OwnerId from lead where lead.id in :LeadIds]; Leads.setOptions(dmo); system.debug('Before Update Lead Details' + Leads); Database.update(Leads,dmo); Lead Leads2=[select id,OwnerId from lead where lead.id in :LeadIds]; system.debug('After Update Lead Details' + Leads2); } }
Here is the test class
@isTest public class TestAssignLeadsUsingAssignmentRules{ static testMethod void createnewlead() { // Test.startTest(); Lead leadToCreate =new Lead(); List<id> Ids= New List<Id>(); // leadToCreate.ownerid= userToCreate.id; leadToCreate.ownerid= UserInfo.getUserId(); leadToCreate.LastName ='Sample1'; leadToCreate.Email='Someone@somewhere.com'; leadToCreate.Company='OneTwo34'; leadToCreate.LeadSource='Partner Referral'; leadToCreate.Country='IN'; leadToCreate.Source_Last_Lead_Source_Detail__c='Form - Contact Form'; insert leadToCreate; Ids.add(leadToCreate.id); AssignLeadsUsingAssignmentRules.leadAssign(Ids); System.assertEquals('00G1W000002RyhMUAS', leadToCreate.OwnerId, 'Something is wrong'); // Test.stopTest(); } }
The test class fails as shown below
this code should work
All Answers
this code should work