+ Start a Discussion
EnryEnry 

Error: Constructor not defined: [ApexPages.StandardController].<Constructor>()

I got this error when i save my test class:

Error: Compile Error: Constructor not defined: [ApexPages.StandardController].<Constructor>() 

 CLASS:

public class ContentVersionAlt {
private List<ContentVersion> ContentVersions;
public string host{get;set;}

    public ContentVersionAlt(ApexPages.StandardController controller) {
           host=URL.getSalesforceBaseUrl().toExternalForm();
    }


    public List<ContentVersion> getContentVersions() {

    ContentVersions= [Select c.id ,c.Software_Download__c,c.title,c.description,c.FileType From ContentVersion c where c.Software_Download__c=:System.currentPagereference().getParameters().get('id')];
        return ContentVersions;
    }

}

 

 

TEST CLASS:

@istest
private class ContentVersionAltTest {
 static testMethod void ContentVersionsTest(){

          PageReference pageRef = Page.SoftwareDownloadFiles;
          Test.setCurrentPageReference(pageRef);

        ApexPages.StandardController sc = new ApexPages.standardController();
        //create an instance of the controller
        ContentVersionAlt myPageCon = new ContentVersionAlt(sc);
        myPageCon.getContentVersions();       

         ContentVersion testContentInsert =new ContentVersion(); 
         testContentInsert.ContentURL='http://www.google.com/'; 
         testContentInsert.Title ='Google.com'; 

         insert testContentInsert;   


         ContentVersion testContent = [SELECT ContentDocumentId FROM ContentVersion where Id = :testContentInsert.Id]; 

         ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace WHERE Name='Opportunity Documents ']; 
         ContentWorkspaceDoc newWorkspaceDoc =new ContentWorkspaceDoc(); 
         newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id; 
         newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId; 
         insert newWorkspaceDoc;

         update testContent; 



 }

}

 

 

 

How can i solve this?

Thanks in advantage for any advice.

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Standard controllers don't have a no-argument constructor - they need an instance of an object to manage, so this line 

 

ApexPages.StandardController sc = new ApexPages.standardController();

will fail.  

 

What is the type of sobject the standard controller is managing (i.e. what is the value of the standardController attribute on the page)?

 

 

 

All Answers

bob_buzzardbob_buzzard

Standard controllers don't have a no-argument constructor - they need an instance of an object to manage, so this line 

 

ApexPages.StandardController sc = new ApexPages.standardController();

will fail.  

 

What is the type of sobject the standard controller is managing (i.e. what is the value of the standardController attribute on the page)?

 

 

 

This was selected as the best answer
EnryEnry

Thanks a lot Bob:

ContentVersion conv=new ContentVersion();
     
        ApexPages.StandardController sc = new ApexPages.standardController(conv);

 

Mohan Raj 33Mohan Raj 33
@bob_buzzard Hello bob, I am also Having that error on my  developer console on execution on my controller as follwingly,
public class AccountListViewController{
public List<Account> AccountsortList {get; set;}
public String SortingExpression = 'name';
public String DirectionOfSort = 'ASC';
//public Integer NoOfRecords {get; set;}
//public Integer Size{get; set;}
    
    public AccountListViewController(ApexPages.StandardSetController controller) {
        AccountsortList = new List<Account>();
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(AccountsortList);
        
       // all();
    }
    
    
    /*public Integer pageNumber {
        get {
        return ssc.getpageNumber();
        }
        set;
    }*/
    public String ExpressionSort {
        get {
            return SortingExpression;
        }
        set {
            If(value == SortingExpression) {
                DirectionOfSort = (DirectionOfSort == 'ASC')? 'DESC' : 'ASC';
            }
            else {
                DirectionOfSort = 'ASC';
                SortingExpression = value;
            }
        }
    
    }
    
    public String getDirectionOfSort() {
        If(SortingExpression == Null || SortingExpression == '') {
            return 'DESC';
        }
        else {
            return DirectionOfSort;
        }
    }
    
    public void setDirectionOfSort(String value) {
        DirectionOfSort = value;
    }
    
    public List<Account>getAccounts() {
        return AccountsortList;
    }
    
     public PageReference ViewData() {
        String FullSortExpression = SortingExpression + ' ' + DirectionOfSort;
        system.debug('SortingExpression:::::'+SortingExpression);
        system.debug(DirectionOfSort);
        
       String Queryitem = ' SELECT Id, Name, Phone, BillingState, Type, Owner.Name, Website FROM Account WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 19';
       system.debug(Queryitem);
       
        AccountsortList = DataBase.query(Queryitem);
        system.debug(AccountsortList);
        return Null;
    }
    
}

Can you help me to remove it sir.
vinay sathivinay sathi
public class PageReference {
    public String name     {set;get;}
    public Integer age     {set;get;}
    public Decimal salary  {set;get;}
    public Decimal exp     {set;get;}
    
    
    public PageReference submit(){
   **  PageReference p=new PageReference('/apex/Result');//Error:Constructor not defined: [PageReference].<Constructor>(String)
      return p;
    }
    public void cancel(){
        name=null;
        age=null;
        salary=null;
        exp=null;
        }

   
}

Getting error at line:9
why?
srikanth maheshwaramsrikanth maheshwaram
Change the class name, do not mention predefined class names of salesforce as your class name..