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
isalewisalew 

Apex Test Auto-Create Record, "sObject type is not supported"

I have built a trigger that creates a custom object when a Lead record meets certain criteria. They are then associated by a lookup relationship.
By manual testing, the trigger works, but how do I write the apex test?

Currently, my code is as follows:

------------------------------------------------------------
@isTest

private without sharing class LC_TestClass{

    static testmethod void CRED_Test(){

    //Insert LD1
    Lead LD1 = new Lead(
        LastName = 'LD1',
        Email = 'LD1@LCA.com',
        Company = 'LCA',
        Status = 'Open - Not Contacted'
    );
    insert LD1;

    //Verify LCA
    LD1 = [SELECT ID, Company, LC_Lead_Company__c, Status, LC_Status__c, OwnerID FROM Lead WHERE ID = :LD1.id];
    LCA = [SELECT ID, Name, OwnerID, Status__c, Lead_Count__c, Domain__c FROM LeadCompay__c WHERE Domain__c = :LD1.LC_Email_Domain__c];

    System.assertEquals( LD1.LC_Company__c,   LCA.Id);
    System.assertEquals( LD1.OwnerId ,     LCA.OwnerId );
    System.assertEquals( 'LCA' ,      LCA.Name );
    System.assertEquals( 'Open - Not Contacted' ,  LCA.Status__c );
    System.assertEquals( '1' ,       LCA.Lead_Count__c );
------------------------------------------------------------

Unfortunately, the developer console gives me the following error from line 18:

sObject type 'LeadCompany__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name...

Any help?
Best Answer chosen by isalew
isalewisalew

The "sObject Type not supported" error was resolved by a basic spelling correction: "LeadCompay__c" on line 18 should have been "LeadCompany__c"

I also improved the query by referencing the relationship between LD1 and LCA in one SOQL query:

LD1 = [SELECT ID, LC_Lead_Company__c, Status, OwnerID, LC_Lead_Company__r.Name, LC_Lead_Company__r.OwnerId, LC_Lead_Company__r.Status__c, LC_Lead_Company__r.Lead_Count__c, LC_Lead_Company__r.Domain__c FROM Lead WHERE ID = :LD1.id];

All Answers

GlynAGlynA
Not sure if this is the problem, but you're using the field "LC_Email_Domain__c" without querying it on the Lead object.

-Glyn
isalewisalew
"LC_Email_Domain__c" is a formula field to extract the "@domain.com" portion of an email, so my adding an email value should take care of that.
Furthermore, I tried declaring this field in the test, and the same error appears.
isalewisalew

The "sObject Type not supported" error was resolved by a basic spelling correction: "LeadCompay__c" on line 18 should have been "LeadCompany__c"

I also improved the query by referencing the relationship between LD1 and LCA in one SOQL query:

LD1 = [SELECT ID, LC_Lead_Company__c, Status, OwnerID, LC_Lead_Company__r.Name, LC_Lead_Company__r.OwnerId, LC_Lead_Company__r.Status__c, LC_Lead_Company__r.Lead_Count__c, LC_Lead_Company__r.Domain__c FROM Lead WHERE ID = :LD1.id];

This was selected as the best answer