function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Naveen Kumar Reddy YerramNaveen Kumar Reddy Yerram 

Method does not exist or incorrect signature: void addAll(List<Account>) from the type List<Opportunity>

Method does not exist or incorrect signature: void addAll(List<Account>) from the type List<Opportunity>

AccoutWrapper_Tests.apxc


@isTest
private class AccountWrapper_Tests {
  @testSetup
  static void loadTestData(){
    List<Account> accounts = (List<Account>) Test.loadData(Account.SObjectType, 'accountData');
    List<Opportunity> opps = new List<Opportunity>();
    for(Account a : accounts){
      opps.addAll(TestDataFactory.createAccountsWithOpps(a.Id, 1000));

ERROR:Method does not exist or incorrect signature: void addAll(List<Account>) from the type List<Opportunity>

    } 
    insert opps;
  }

  @isTest static void testPositiveRoundedAveragePrice() {
    List<AccountWrapper> accounts = new List<AccountWrapper>();
    for(Account a : [SELECT ID, Name FROM ACCOUNT]){
      accounts.add(new AccountWrapper(a));
    }
    // sanity check asserting that we have opportunities before executing our tested method.
    List<Opportunity> sanityCheckListOfOpps = [SELECT ID FROM Opportunity];
    System.assert(sanityCheckListOfOpps.size() > 0, 'You need an opportunity to continue');
    Test.startTest();
    for(AccountWrapper a : accounts){
      System.assertEquals(a.getRoundedAvgPriceOfOpps(), 1000.00, 'Expected to get 1000.00');
    }
    Test.stopTest();
  }
    

      @isTest static void testHighPriority() {
        List<AccountWrapper> accounts = new List<AccountWrapper>();
        for(Account a : [SELECT ID, Name FROM ACCOUNT]){
            accounts.add(new AccountWrapper(a));}

          
            List<Opportunity> opps = new List<Opportunity>();
            opps = [SELECT Id,Amount FROM Opportunity];
              for(Opportunity opp :opps ) {
                  opp.amount =2000000;
              }
          update opps;
    
    Test.startTest();
      for(AccountWrapper a : accounts){
      System.assertEquals(a.isHighPriority(), true, 'Priority expected to be high');
      System.debug('get rounded price of opps for accounts b:'+ a.getRoundedAvgPriceOfOpps());
    }
    Test.stopTest();
  }
}

TestDataFactory.apxc

@isTest
public class TestDataFactory {
    public static List<Account> createAccountsWithOpps(Id AccountId, Integer Amount) {
        List<Account> accounts = new List<Account>();
        
        for(Integer numAccts, i=0;i<numAccts;i++) {
            Account a = new Account(Name='TestAccount' + i);
            accounts.add(a);
        }
        insert accounts;
        
        List<Opportunity> opps = new List<Opportunity>();
        for (Integer numAccts, j=0;j<numAccts;j++) {
            Account a = accounts[j];
            // For each account just inserted, add opportunities
            for (Integer numOppsPerAcct, k=0;k<numOppsPerAcct;k++) {
                opps.add(new Opportunity(AccountId=a.Id,
                                       Amount=1000));
            }
        }
        // Insert all opportunities for all accounts.
        insert opps;
        
        return accounts;
    }
}

 
Suraj Tripathi 47Suraj Tripathi 47
Hi,

In your code :-
 for(Account a : accounts){
      opps.addAll(TestDataFactory.createAccountsWithOpps(a.Id, 1000));
   } 

TestDataFactory.createAccountsWithOpps(a.Id, 1000) is returning List of Accounts ( return accounts;) and you are adding these accounts in List of Opportunity.
TestDataFactory is already creating opportunities so you may not need to insert opportunities in your code.


Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi