I'm trying to assign account Id to quote, but i can't even compile code, becouse of this error message: Field is not writeable: Quote.AccountId

Sample code:

Account acc = new Account(name='Test Acc');
insert acc;
Quote qu = new Quote(name='01010', accountId=acc.Id);

I know, that Quote has some required fields, but for the sake of simplicity, this sample code is assigning just accountId.

Is there some known workaround?

1 Answer 1


You can't set the accountId of Quote directly. It will be set by Salesforce with the accountId of the Opportunity related to this Quote.

Ran this code and print the quote variable and it have the accountId assigned.

Account acc = new Account(name='Test Acc');
insert acc;
Opportunity o = new Opportunity(AccountId = acc.Id,name = acc.name,closedate = system.today(),stagename='Prospecting');
insert o;
Quote qu = new Quote(name='01010', opportunityId=o.Id);
insert qu;
qu = [select id,name,opportunityid,accountid from quote where id =: qu.id];

According to the documentation accountId doesn't have create and update properties and opportunityId just have create property.

Hope it helps.

  • I suspected as much. Strange that, according to the documentation, the field is writeable. That is to say, it is not explicitly described as 'read-only'. Apr 13, 2016 at 13:25
  • 3
    @SanderdeJong It is not writeable. It is not creatable and updatable also. See the document link i have provided. Apr 13, 2016 at 13:33
  • Hmm. I had seen that page as well and concluded that it was writeable, because it doesn't have the read-only statement that the attribute AdditionalAddress, just below, has. Thanks for the added explanation! Apr 13, 2016 at 13:53

You must log in to answer this question.

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