I have a test class that is failing due to too many SOQL queries. I'm assuming the fix is quite easy, but am struggling with how to bulkify the query. Can someone please assist? Full test class is below.
@isTest
private class clsUpdateAccountFieldsFromUserTable {
static testMethod void verifyLUXIDSetFromOwner(){
// Perform our data preparation.
Profile p = [select id from profile where name='Standard User'];
User u = new User(alias = 'standt', email='[email protected]',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/New_York', username='[email protected]',
LUX_ID__c ='01234567');
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 200; i++){
Account a = new Account(Name = 'Test Account ' + i);
accounts.add(a);
}
// Start the test, this changes governor limit context to
// that of trigger rather than test.
test.startTest();
// Insert the Account records that cause the trigger to execute.
System.runAs(u){
insert accounts;
}
// Stop the test, this changes limit context back to test from trigger.
test.stopTest();
// Query the database for the newly inserted records.
List<Account> insertedAccounts = [SELECT Name, Owner_LUX_ID__c
FROM Account
WHERE Id IN :accounts];
// Assert that the Description fields contains the proper value now.
for(Account a : insertedAccounts){
System.assertEquals(
'01234567',
a.Owner_LUX_ID__c);
}
}
}