I have this error when I run my test class, and I can't find how to resolve it, here is the test method :

static testMethod void FSControllerTest (){
    Account acc= new Account(Name = 'test');
    insert acc;

    Opportunity opp= new Opportunity(Name = 'nomOpp', AccountId = acc.Id, CloseDate = date.newInstance(2017, 02, 02));
    insert opp;

    Contact contact = new Contact(FirstName = 'fisrtName', LastName = 'LastName', AccountId = acc.Id);
    insert contact;

    FSController controller = new FSController (new ApexPages.StandardController(opportunite)); //the error is at this line


And a sample of the controller to see where the error appens :

 public Opportunity opp{get; set;}
 public FSController (ApexPages.StandardController controller){
    this.opp= (Opportunity)controller.getRecord();

    acc = [SELECT Id, Name FROM Account WHERE Name=:opp.Account.Name LIMIT 1]; //the line where the error appens

the Standard controller of my visulaforce page is Opportunity.

1 Answer 1


I will assume that the several wrong variable names are just some problems inserted while you were writing your question ("opportunite" instead of "opp").You are requesting the account name instead of its Id. Here's the solution:

acc = [SELECT Id, Name FROM Account WHERE Id=:opp.AccountId LIMIT 1];
  • Ah yes sorry for the errors in variables names (I updated the question) and thank you for your answer !
    – dou
    Commented Jan 11, 2017 at 13:55
  • I guess you're french because of the variable names :D De rien Commented Jan 11, 2017 at 13:56
  • C'est bien de voir des français ici!
    – Adrian Larson
    Commented Jan 11, 2017 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .