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
Vadivel MuruganVadivel Murugan 

Error for isRunningTest()

public PageReference SaveasPdf(){
 Blob b;
 Attachment newAttach = new Attachment();
 PageReference ref = Page.Hydrant_Service_Sheet;

 if(!Test.isRunningTest())  // Error: Compile Error: Method does not exist or incorrect signature: [String].isRunningTest() at line 18 column 6
 b = ref.getContentAsPDF();
 b = Blob.valueOf('Unit Test Attachment Body');

 newAttach.Name = 'Uplift Request';
 newAttach.ParentId = currentid;
 newAttach.Body = b;
 Insert newAttach;
 PageReference pageRef = new PageReference('/'+currentid);
 return pageRef;

Error occured in above. But i have check code is correct. if any one konow i do anymistake this rely...........
Hitendar Singh 9Hitendar Singh 9

Make sure that you dont have any other class named 'Test'. Because compiler will search for the isRunningTest method in that class.

Also make sure you do not have any variable named 'Test'
Amit Chaudhary 8Amit Chaudhary 8
Did you add a class to your org named Test or any variable ?

If you add an Apex Class with the same name as a default class in Apex, all calls to that class will look at your class instead of the standard Apex classes.

Your code is good.