private class methodonetest {
    private static Account acc;
        private static Opportunity  Opp;
        private static Quote  Q;
        private static Product2 prd;
        private static QuoteLineItem Qli;

    @testSetup static void testData(){

        acc = new Account();
        acc.Name = 'TestAccount';
        insert acc; 

        Opp = new Opportunity(Name=acc.Name + ' Opportunity ',

                                       StageName='Prospecting',start_date__c = system.today(),end_date__c = system.today()+45,



        insert Opp;

        prd = new product2(name='unittestproduct');

        prd.Family = 'License';

        insert prd;

       Pricebook2 stdPb = [select Id,name, isactive from Pricebook2 where IsStandard = true limit 1];
       //Id t = Test.getStandardPricebookId();
        //insert stdPb;
        PricebookEntry pbe = new PricebookEntry(pricebook2id = stdPb.Id, product2id = prd.id,unitprice=1.0,isActive=true);
        insert pbe;
         q=new quote(name='myquotetest',opportunityid=opp.id,pricebook2id=stdPb.Id, status='Draft');
        insert q;
        quoteLineItem i = new quotelineitem(); 
        i.quoteid      = q.id; 
        i.pricebookentryid    = pbe.id; 
        i.quantity            = 1; 
        i.unitprice           = 1; 
              insert i; 

    static void testApexPageMessages(){

         //CreateOrderFromQuote s = new CreateOrderFromQuote();    

This is my test class. I'm getting the error:

Test class containing a test setup method cannot have any methods annotated with @isTest(​SeeAllData=​true)

I need seeattdata=true as i;m using standard pricebbok2. can someone help me how to solve the issue?

  • This situation is exactly as error says. Hence why don't you setup the required test data without the @testSetup annotation. If it is governor limits for the actual test that you are worried about, then test.startTest and test.stopTest can give you a fresh context just for testing out the logic. – Prajith Feb 11 '16 at 17:46
  • You also do not need to use SeeAllData = true , to test logic related to pricebooks. We can set it up along with test data. Please see official release notes - releasenotes.docs.salesforce.com/en-us/summer14/release-notes/… – Prajith Feb 11 '16 at 17:48

According to this link

Test Setup Method Considerations

Test setup methods are supported only with the default data isolation mode for a test class. If the test class or a test method has access to organization data by using the @isTest(SeeAllData=true) annotation, test setup methods aren’t supported in this class.

So either remove the annotation of @testsetup and call your static method in the test method or try and do the test without the SeeAllData attribute

| improve this answer | |

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.