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
max_overloadmax_overload 

Test class help. Getting a required field exception

Here's the code for the class:

 

@isTest
private class JSLeadAssignmentTestClass {

    static testMethod void triggertest() {
        //Create new lead record
        Lead l = new Lead(firstname='test' , lastname='apex' , company='Oracle', LeadSource='Jigsaw');
        insert l;
    }   

 

 

When using the Apex Test Runner in Eclipse, I receive the error:

EXCEPTION_THROWN|[10,9]|System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company]: [Company]

 

Any help would be greatly appreciated

 

Nick34536345Nick34536345

that code works for me

do you have an insert trigger on Leads and what does it do?

max_overloadmax_overload

Thanks for your reply, Nick. I do have a trigger on lead after insert/update. It pushes the lead through assignment rules and updates accordingly.

 

trigger JSLeadAssignmentTrigger on Lead (after insert){
  for (Integer i=0; i < trigger.new.size(); i++){
    if (trigger.new[i].LeadSource == 'Source1')
    {
      Database.DMLOptions dmo = new Database.DMLOptions();
      dmo.assignmentRuleHeader.useDefaultRule= true;
      trigger.new[i].setOptions(dmo);
      database.update(trigger.new[i]);
    }
  }
}