1

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, 値を入力してください: [Company]: [Company]

Getting the above error when running the test class. However, when i try to enter company into the designated area (code below), it tells me the variable does not exist.

 Lead leds = new Lead(lastname='Test', email='1@2.com', company='Test');
    insert leds;

    user u = [select ID from User where ID ='00536000008S5wA'];


System.runAs(u) {
    //Insert our first task
    Task t = new Task(subject='Test Activity', whoId = leds.id);
    insert t;

    Lead l = new Lead() ;
    l.LastName ='Test';

    // .. Add other fields 
    l.Number_of_Activities__c  =1 ;
    insert l ; 
1

The field Company is mandatory for the Lead object unless you have Person Accounts activated. On your test code, set l.Company to a test value and your code should work.

For Example, add to your test code the following line

l.company = ‘Test’;

PS: you should never hardcode a Id in your code, try creating your own user instead. That way your code will continue to work even if the designated user is deactivated or deleted.

0

You used a Hardcoded Id so that is not in the best practices in Salesforce. And you have missed mandatory fields Company and a status field. please try the below code:

@isTest public class TestClass {

  @isTest
 public static void test(){
    Lead leds = new Lead(lastname='Test', email='1@2.com', company='Test',Status='Working-Contacted');
    insert leds;
    // u1=UserInfo.getUserID();
    //user u = [select ID from User where ID ='00536000008S5wA'];
     System.runAs(new user(ID = UserInfo.getUserID())){

        //Insert our first task
        Task t = new Task(subject='Test Activity', whoId = leds.id);
        insert t;

        Lead l = new Lead() ;
        l.LastName ='Test';
        l.Company='Ca';
        l.Status='Working-Contacted';    
        // Add other fields 
        l.Number_of_Activities__c  =1 ;
        insert l ; 
    }



}

}

Please select it as Best answer if you find it helpful.

Thank You,

Ajay Dubedi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.