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
Erik John PErik John P 

required company field is missing on test classes, but I show it in test

Hello all! 

I feel that I am almost there on an inbound changeset from sandbox to prod.  I am however getting an error that "required fields are missing [Company]; [Company]."   this is the error on 4 test classes, one of which is below.  I'm perplexed because the one below has company in the test class, so not sure why I'm still seeing the error.  on this one at least.

@istest
private class ELQA_Leadconvert_updateTest{
    static testmethod void positivetest() {
        Lead testlead = new Lead();
        testlead.firstname = 'test first';
        testlead.lastname = 'test last';
        testLead.company = 'Test Co';
        testLead.email = 'test@gmail.com';
        TestLead.TS_Factory__c ='TS00020';
                // added all required field here
        insert testlead;
        
        /*Added by Greytrix to emailsToChangeInEloqua part*/
        testLead.email = 'test1@gmail.com';
        update testlead;
        /*Modifications by Greytrix ends*/
        //Start the test 
        test.starttest();
        database.leadconvert testLeadConvert = new database.leadconvert();
        testLeadConvert.setleadID(testlead.id); 
        /*Modifications by Greytrix starts*/
        //set no Opportunity to be created after conversion
        testLeadConvert.setDoNotCreateOpportunity(false);
        //fetch the label for the Converted status for lead, and set the value
        LeadStatus convertStatus = [Select Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        testLeadConvert.setConvertedStatus(convertStatus.MasterLabel);
        //Convert the lead
        Database.LeadConvertResult lcr = Database.convertLead(testLeadConvert);
        System.assert(lcr.isSuccess());
        /*Modifications by Greytrix ends*/
        //Stop the test
        test.stoptest();
    }
}
Amit Chaudhary 8Amit Chaudhary 8
What Error you are getting ? Your this class look good to me. Is same test class failing while deployment ? if other then please post screen shot and error class
Dushyant SonwarDushyant Sonwar
Erik ,Is there any before trigger on lead in production that is clearing the company field? This class also seems to be good to me as amit said.
 
Erik John PErik John P
Error message as follows: System.DmlException: Insert Failed. First exception on row 0; First Error: REQUIRED_FIELDS_ARE_MISSING, Required fields are missing: [Company]:[Company]. Screenshot of the error messages below. Let me know if the snip doesn’t come through in the email. Yes this is failing at deployment into prod. I read something on the community about that field possibly being a roll up to another object, and should place a “record type ID” in my code. I attempted to add “TestLead.recordtypeid = '01261000000XgVeAAK';”. Still need to check if this will work. So the entire test class is as follows: @istest private class ELQA_Leadconvert_updateTest{ static testmethod void positivetest() { Lead testlead = new Lead(); testlead.firstname = 'test first'; testlead.lastname = 'test last'; testLead.company = 'Test Co'; testLead.email = 'test@gmail.com'; TestLead.TS_Factory__c ='TS00020'; TestLead.recordtypeid = '01261000000XgVeAAK'; // added all required field here insert testlead; /*Added by Greytrix to emailsToChangeInEloqua part*/ testLead.email = 'test1@gmail.com'; update testlead; /*Modifications by Greytrix ends*/ //Start the test test.starttest(); database.leadconvert testLeadConvert = new database.leadconvert(); testLeadConvert.setleadID(testlead.id); /*Modifications by Greytrix starts*/ //set no Opportunity to be created after conversion testLeadConvert.setDoNotCreateOpportunity(false); //fetch the label for the Converted status for lead, and set the value LeadStatus convertStatus = [Select Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1]; testLeadConvert.setConvertedStatus(convertStatus.MasterLabel); //Convert the lead Database.LeadConvertResult lcr = Database.convertLead(testLeadConvert); System.assert(lcr.isSuccess()); /*Modifications by Greytrix ends*/ //Stop the test test.stoptest(); } } [cid:image001.png@01D2195A.7C96E2E0] Erik Peterson | Application Support Analyst Tuff Shed, Inc. | IT Department Phone: 303-474-5684 Email: epeterson2@tuffshed.com
Erik John PErik John P
Hello Dushyant, I just replied to Amit, didn’t see your post. I apologize, but I am very new to dev, I do not know what a before trigger would look like. But I’m guessing it’s possible. In my response to Amit, I mentioned reading something about the field I am getting an error on, Company. If it is a roll up field, and I believe mine is, I need to refer to a “record type ID”. I might try that…thank you for your response. Erik Peterson | Application Support Analyst Tuff Shed, Inc. | IT Department Phone: 303-474-5684 Email: epeterson2@tuffshed.com