+ Start a Discussion
System Administrator 393System Administrator 393 

Unable to make an Account Object and set its name in Apex Test Class

I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new I have an Apex Class Test in which I need to create a new Account Object and set its name, however when I use Account acc = new Account(Name = 'ABC'), it shows me invalide field Name but Name is the API Name of the field in the Account Object, Can anyone please help me?
Ajay K DubediAjay K Dubedi
Hi,
Used below code its work for me :
- Put class name and method Name acoording to your code.
@isTest
public class AccountProcessorTest {
    @isTest static void countContacts_Test(){
        Account accObj = new Account();
        accObj.Name = 'Account test';
        insert accObj;
  Test.startTest();
        ClassName.MethodName();//Method should be static
        Test.stopTest();
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
System Administrator 393System Administrator 393
Thank you so much, this worked.