REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]

when i trying to insert opportunity in my testclass i am getting an error

   Test_opportunityTrigger.Test_opportunityTrigger: line 24, column 1
   22:28:17.312 (312087000)|FATAL_ERROR|System.DmlException: Insert failed. First      exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]:        [Name]

But i have name field in opportunity My code :

            Opportunity op = new Opportunity();
    op.RecordTypeId = rt.Id;
    //op.AccountId =;
    op.Name = 'OppName';
    op.City__c = 'OppCty';
    op.Postal_Code__c = '12345';
    op.State__c = 'opp_sta';    
    op.Copy_Account_BA_to_SA__c = true;
    op.Street__c = 'OppStr';
    op.CloseDate =;
    op.StageName = 'No Decision';
    op.Email_Field__c = '';        
    insert op;

Insert op is at line 24. Do anybody have any idea.


Is it possible that your trigger, being a before insert, somehow nulls out the Name field before the insert happens?

If that is not happening, I would also check to see if you run any DML statements on other objects during your before insert trigger. This error may not be related to the opportunity but rather a separate object that is being created in your before insert trigger code that has a null Name field.

Also, as Peter pointed out below, this could also be a workflow rule. If for some reason you have a workflow rule that nulls out your Name field after it has been originally saved, your before/after triggers and validation will run again. This issue could pop up in this scenario as well.

If none of these are correct, update your question with your trigger code and let us take a look.

Source : Link , Question Author : AnuRaj , Answer Author : Jesse Altman

Leave a Comment