You need to sign in to do that
Don't have an account?
Andrey Bolkonsky
Convert Lead Test Class is Not Working
I've made a class that converts leads and also a Test Data Factory class that makes test leads.
However My below test class is not working. When I used System.Assert(), I get the error System.AssertException: Assertion Failed
When I used System.AssertEquals(Lead1.IsConverted, TRUE) I get the error System.AssertException: Assertion Failed: Expected: false, Actual: true
What am I doing wrong?
However My below test class is not working. When I used System.Assert(), I get the error System.AssertException: Assertion Failed
When I used System.AssertEquals(Lead1.IsConverted, TRUE) I get the error System.AssertException: Assertion Failed: Expected: false, Actual: true
What am I doing wrong?
@isTest global class ConvertLeadTest { @isTest static void convertOneLead(){ Lead[] TestLeads = TestDataFactory2.getTestLeads(1); List<Id> IdsIn = new List<Id>(); for(Lead Lead : TestLeads){ IdsIn.add(Lead.Id); } insert TestLeads; Lead Lead1 = TestLeads[0]; ConvertLead.LeadsToConvert(IdsIn); System.assert(Lead1.IsConverted); } }
You can keep the insert the Test Leads in the Test Class but it should be above the for loop. Inside the loop you are accessing the Id so it's need to inserted before loop.
You need to query the lead record to see the latest changes in test class after some logic execution.
Thanks,
Maharajan.C
All Answers
Execute the below code and see the debugs. If you are not getting isconverted as true in debug line below the query then your actual class is not converting the test lead.
Thanks,
Maharajan.C
it seems since I tried to insert the Test Leads in the Test Class, it did not work. However Once I moved the Insert statement to the end of the Test Data Class it worked.
Can you please tell me why is it that the first debug statement is showing false, but the debug statment after the Query is showing true?
You can keep the insert the Test Leads in the Test Class but it should be above the for loop. Inside the loop you are accessing the Id so it's need to inserted before loop.
You need to query the lead record to see the latest changes in test class after some logic execution.
Thanks,
Maharajan.C