4

I have a difficult issue because I have essentially a standardcontroller that runs off the current opportunity but it needs to be used via a relatedlist button on a custom object so it has to be a standardsetcontroller to be recognized by the custom object. I have it working but when trying to create the test class I cannot get it to recognize the controller. I just keep getting the error Compile Error: Constructor not defined: [ApexPages.StandardSetController].(Id)

Here is the start of my extension class up to where it instantiates the controller

public with sharing class opportunityContactEntryExtension {

  public Opportunity theOpp {get;set;}
  public String searchString {get;set;}
  public Opportunity_Contact_Role__c[] chosencontacts {get;set;}
  public contact[] availablecontacts {get;set;}
  public Account theAccount {get;set;}   

  public String toSelect {get; set;}
  public String toUnselect {get; set;}
  public Decimal Total {get;set;}

  public Boolean overLimit {get;set;}

  private Opportunity_Contact_Role__c[] forDeletion = new Opportunity_Contact_Role__c[]{};

  public opportunityContactEntryExtension(ApexPages.StandardsetController controller) {
    Id opptyId = ApexPages.currentPage().getParameters().get('id');

    // Get information about the Opportunity being worked on
    theOpp = [select Id, AccountId, Account.Name from Opportunity where Id = :opptyId limit 1];
  }
}

and this is the start of my test class up to where it gives the error:

@istest
private class testopportunitycontactEntry {

static testMethod void theTests(){
    //Create Test Data

    Account a=new Account(Name='Test Account');
    insert a;
    Contact c = new Contact(FirstName='John',LastName='Doe');
    insert c;
    Opportunity o = new Opportunity(Name='Test Opportunity',closedate=system.today(), stagename='Confirmed Teaching/Class Schedule',Probability=0.95);
    insert o;      
    Opportunity_Contact_Role__c cocr = new Opportunity_Contact_Role__c (Opportunity__c = o.id, Contact__c=c.id, role__c='Decision Maker', Primary__c=True) ;     
    insert cocr;  

    ////////////////////////////////////////
    //  test opportunityContactEntry
    ////////////////////////////////////////

    // load the page       
    PageReference pageRef = Page.opportunitycontactEntry;
    pageRef.getParameters().put('Id',cocr.Opportunity__c);
    Test.setCurrentPageReference(pageRef);

    // load the extension
    opportunityContactEntryExtension oCEE = new OpportunityContactEntryExtension(new ApexPages.StandardSetController(cocr.Opportunity__c));
 }
}
6

Why don't you create a collection of 1 to pass into your constructor? e.g.

List<Opportunity> opps = new List<Opportunity>();
opps.add( [ Select Id From Opportunity Where Id = : cocr.Opportunity__c ] );
opportunityContactEntryExtension oCEE = new OpportunityContactEntryExtension(new ApexPages.StandardSetController( opps ));

At the moment, you're just passing in cocr.Opportunity__c which is an Id of the Opportunity and there is no constructor that accepts Id for the StandardSetController class.

See the docs here.

  • That was it. I had tried adding a list before and it wouldn't let me...I got an error saying that List was unexpected or something like that. I must have done something wrong though because this time it let me add it. That was it! – user2769 May 1 '13 at 17:21

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.