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
Liam Lu 10Liam Lu 10 

Assign detail object to its master object

Hello I am writing a test calss and I need create a quote object for testing purpose. However, quote(Detail) has a master-detail relarionship with opportunity object (Master). There fore when I wrote "Quote.Opportunity.Id=Opportunity.ID", it reports "Deference a NULL value " Error. Is there anyone know why is this happening and how to fix it? Any help is appreciated. 

Here are my codes:
Opportunity O = new Opportunity();
        O.Name='sss';
        O.AccountId=A.ID;
        O.LeadSource='Other';
        O.Type='New Business';
        O.CloseDate=myDate;
        O.StageName='Qualify';
        O.CurrencyIsoCode='CAD';
        
        Insert O;
        
        Quote Q=new Quote();
        Q.Name='TestQuote';
        Q.Status='Deaft';
        Q.Payment_Terms__c='Payment Schedule';
        Q.FOB__c='Our Shop';
        Q.Freight__c='Collect';
        Q.Lead_Time__c='TBA';
        Q.Email='liam@shaverinc.com';
        Q.ShippingState='ON';
        Q.Opportunity.Id=O.Id;
        Insert Q;

Thank you!
Best Answer chosen by Liam Lu 10
Anil MalneniAnil Malneni
Update line number 21 as below...

Q.OpportunityId=O.Id;


Thank you,
Anil
 

All Answers

Anil MalneniAnil Malneni
Update line number 21 as below...

Q.OpportunityId=O.Id;


Thank you,
Anil
 
This was selected as the best answer
Liam Lu 10Liam Lu 10
Thanks a lot! That was a silly mistake. _____