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
asd@as.asdasd@as.asd 

Error in Test.startTest() method

hello 

    i am using test,startTest()  and test.stopTest() method in test class.

   i am  facing a error   :

    Method does not exist or incorrect signature: Test.startTest() at line 16 column 9

    my code is : 

       

 

      

@isTest

private class testclass{

public static testMethod void TestOverwriteTestAccountDescriptions(){
// Perform our data preparation.
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.
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, Description 
FROM Account 
WHERE Id IN : accounts];

// Assert that the Description fields contains the proper value now.
for(Account a : insertedAccounts){
System.assertEquals(
'This Account is probably left over from testing. It should probably be deleted.', 
a.Description);
}
}
}

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

I think you have another apex class caleed "Test". That's why you are getting this error. Check for it.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Chamil MadusankaChamil Madusanka

Try

 

System.test.startTest();

 instead of

 

test.startTest();

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Chamil MadusankaChamil Madusanka

I think you have another apex class caleed "Test". That's why you are getting this error. Check for it.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
asd@as.asdasd@as.asd

thanks for reply

       now  i have solved  this problem.

       actually  a apex class named as test is alredy exist.

       now i rename that class.

      my code is working now

Chamil MadusankaChamil Madusanka

Yeah, If you want to keep your class called Test, then you have to use System.Test.startTest()

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

nandu s 15nandu s 15
Yes! i have another Test class...renamed... the error was removed thanks