+ Start a Discussion

Insert an opportunity by apex code

I try to insert a new opportunity by this way. The account field in opportunity is Lookup type. My code below shows that I got a row for Account but there is nothing in Account Name shown on the page for this opportunity after running this code.
Any idea is appreciated.  many thanks
Opportunity opp = new Opportunity(Name = 'fromtrigger',Type ='New Customer', Account= [Select Id From Account where name = 'test00'],CloseDate=Date.valueOf('2008-04-28'),StageName='Prospecting'); 
insert opp;
I already got the answer. That is I need to use AccountId to asscociate an opportunity to the exact account. For example
CampaignId =[select Id from Campaign where name ='Campaing01'].Id   ---  That works
Campaign =[select Id from Campaign where name ='Campaing01'] --- doesnt work