function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DTRain521DTRain521 

Test Class External Entry Point Error

Hi everyone,

I am having an issue with a test class.  During the System.assertEquals() process I am getting an External Entry Error.

 

I am new at developing and could use your experteise on this issue.  My code is shown below.

 

 

@isTest
class TestConvertCLLeadController
{
    final static String clauto = 'CL Auto';
    
    static testMethod void testConvertCLLeadController()
    {
        //We run our unit test as this user
        User testSysAdminUser = new User(alias = 'standt', email='standarduser@testorg.com', 
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', 
            localesidkey='en_US', profileId = [select id from profile where name='System Administrator' LIMIT 1].Id, 
            timezonesidkey='America/Los_Angeles', username='ASstandarduser@testorg.com');
            
        insert testSysAdminUser;
        
        System.runAs(testSysAdminUser)
        {
            Lead lead = new lead (LastName = 'TEST1',
                                  Company = 'TEST1',
                                  OwnerId = UserInfo.getUserId(),
                                  Consumer_Products__c = clauto,
                                  Agent_Code__c = 'TEST1',
                                  Email = 'test@test.com',
                                  Billing_Street__c = '1234 W TEST AVE',
                                  Billing_City__c = 'Boston');
                                 
            insert lead;
            
            ApexPages.currentPage().getParameters().put('id', lead.Id);
            ApexPages.StandardController sc = new ApexPages.StandardController(lead);
            Test.startTest();
    
            ConvertCLLeadController clc = new ConvertCLLeadController(sc);
            clc.clautoQuoteValue = true;

            clc.convertLead();
            
            Id accountId = [SELECT ConvertedAccountId FROM Lead WHERE Id =: lead.Id].ConvertedAccountId;
error occurs at this point..........
            System.assertEquals(6, [SELECT count() FROM Opportunity WHERE AccountId =: accountId]);
            System.assertEquals(0, [SELECT count() FROM Contact WHERE AccountId =: accountId]);

 

 

Thanks You so much for your help.

Dwayne

Best Answer chosen by Admin (Salesforce Developers) 
DTRain521DTRain521

OK So I happened to find the issue as I started looking at the code again.  

 

The 6 was the issue.  It was expecting 6 items but actually received 1.  Changed my code to look for one and then added more to the code to cover more lines.  Works great and gave me 90% code coverage.  YEAH!!!!

 

So..Not sure if this is really the best way to write the code but it is the only way that I could figure it out.  Any other suggestions are must appreciated.

All Answers

Damien_Damien_

I don't think that you have a value for ConvertedAccountId.  If your error is occuring on the assert that would be why.

DTRain521DTRain521

Thank you for your response.  

 

Sorry to be thick headed but what would be the best way to apply a value?

Damien_Damien_

Well I don't know how exactly you have your database setup but something like

 

lead.convertedAccountId = avalue;

 

If it's just a normal account and you don't care what account you fetch you could do something like

 

lead.convertedAccountId = [SELECT id FROM Account LIMIT 1].id;

 

This will probably make your asserts fail though so you will still get an error.  I'm not sure you are trying to test this correctly, because if you add records in the future that 0 and 6 would cause your cases to fail in the future even if it succeeded now.

DTRain521DTRain521

I would prefer to set it up so that it could be useful later down th road.  What would be your suggestion on fixing this?  I am new to writing test classes and apex code and can use all the help I can get.  :smileysad:

Damien_Damien_

To be honest, I'm writing my first real test class write now myself.  I mainly just have the conceptual grasp on it as of now.  I suggest either trying to look at examples or asking someone else to help you with it.  Sorry for my limited help.

DTRain521DTRain521

OK... Thank You so much for trying.  I will see if anyone else posts.

I really appreciate your help.

DTRain521DTRain521

OK So I happened to find the issue as I started looking at the code again.  

 

The 6 was the issue.  It was expecting 6 items but actually received 1.  Changed my code to look for one and then added more to the code to cover more lines.  Works great and gave me 90% code coverage.  YEAH!!!!

 

So..Not sure if this is really the best way to write the code but it is the only way that I could figure it out.  Any other suggestions are must appreciated.

This was selected as the best answer