You need to sign in to do that
Don't have an account?
Dan Lambeth 31
why does this attempt to create an account from a test class fail?
@testSetup
static void setup() {
List<Account> accounts;
// get some account Ids -- we will just create a couple of dummies
System.debug ('AccountProcessorTest.setup() entered');
try {
accounts.add (new Account (name = 'who cares'));
accounts.add (new Account (name = 'who cares 2'));
insert accounts;
System.debug (accounts.size() + ' accounts created');
}
catch (Exception e) {
System.debug('The following exception of type ' + e.getTypeName() + ' has occurred: ' + e.getMessage());
}
The method consistently fails at the first accounts.add() call.
09:37:52:002 USER_DEBUG [19]|DEBUG|The following exception of type System.NullPointerException has occurred: Attempt to de-reference a null object
There are no validation rules on account. I can create this account via the UI supplying nothing but the name.
thanks in advance
static void setup() {
List<Account> accounts;
// get some account Ids -- we will just create a couple of dummies
System.debug ('AccountProcessorTest.setup() entered');
try {
accounts.add (new Account (name = 'who cares'));
accounts.add (new Account (name = 'who cares 2'));
insert accounts;
System.debug (accounts.size() + ' accounts created');
}
catch (Exception e) {
System.debug('The following exception of type ' + e.getTypeName() + ' has occurred: ' + e.getMessage());
}
The method consistently fails at the first accounts.add() call.
09:37:52:002 USER_DEBUG [19]|DEBUG|The following exception of type System.NullPointerException has occurred: Attempt to de-reference a null object
There are no validation rules on account. I can create this account via the UI supplying nothing but the name.
thanks in advance
Hi,
Please try the below code.
Please mark it as the Best Answer if it helps you.
Thank You
All Answers
Hi,
Please try the below code.
Please mark it as the Best Answer if it helps you.
Thank You
You can take reference from the below test class:- In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.