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
SuzanyuSuzanyu 

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;
SuzanyuSuzanyu
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
 
but
Campaign =[select Id from Campaign where name ='Campaing01'] --- doesnt work