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

Invalid Initial Expression Type for Field

Hi everyone, I'm new to the world of apex and such and I'm working on my first test class.  So far I have managed to get most of the code working, but now I'm stuck, and no amount of googling is solving the problem, so any input would be appreciated, I'm sure this is an easy fix for people here.


I'm getting this error in Eclipse: "Invalid Initial Expression Type for Field Quote.OpportunityID, Expecting: Id."  It is coming from this block of code:


Quote quo = new Quote

            (Name = 'Superstar', OpportunityID = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend']);

         insert quo;


I'm at a loss.  Any input would be helpful.  Here's the rest of the code if that would help any:



private class PFIFillTest {


    static testMethod void myUnitTest() {

    Account acc = newAccount

    (Name = 'TestCo');

    insert acc;

         Opportunity opp = newOpportunity

            (Name = 'WillitBlend', Account = [SELECT Id, Name FROM Account Where Name = 'TestCo'], 

            StageName = 'Proposal/Price Quote', CloseDate =,

            ForecastCategoryName = 'Best Case');

         insert opp;

         Quote quo = new Quote

            (Name = 'Superstar', OpportunityID = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend']);

         insert quo;

         QuoteLineItem qli = newQuoteLineItem

         (UnitPrice = 2500, Quantity = 1, Description = 'Wahoo');

         insert qli;


       update qli;


qli = [SELECT id, Project_For_Invoicing__c FROM QuoteLineItem WHERE Description = 'Wahoo'];

       system.assert(qli.Project_For_Invoicing__c != null);



Best Answer chosen by Admin (Salesforce Developers) 
Anup JadhavAnup Jadhav

If you change this line as follows, it should fix the problem.


Quote quo = new Quote

            (Name = 'Superstar', OpportunityID = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend'].Id);

 better still, just to make it clear.


Id oppId = [SELECT Id FROM Opportunity WHERE Name = 'WillitBlend'].Id;

Quote quo = new Quote(Name = 'Superstar', oppId);

   - anup