Quote quote = new Quote();
quote.Name = 'TEST';
quote.BillingName = 'ROY';// This is the 'Bill To Name' field
quote.BillingAddress.BillingStreet = 'KOCHI';//Is this the right way?
insert quote;

Actually, 'Bill To' field consist of these fields:
Bill To:
Bill To Street
Bill To City
Bill To State
Bill To Zip/Postal Code
Bill To Country

How to set values to these fields through apex?

Please help me on this


2 Answers 2


The same way you set any other field, really.

Fields like BillingAddress and ShippingAddress are compound fields.

Compound fields are accessible as a single, structured field, or as individual component fields. The values contained within the compound field and the values in individual fields both map to the same underlying data stored in Salesforce; they always have identical values. Code that references individual component fields is unaffected by the new compound fields.

Compound fields are read-only. Changes are performed by writing to the individual component fields. This maintains a single, consistent method for performing updates, and avoids the possibility of conflicts. For example, if both the BillingAddress compound field and BillingCity individual component field were updated in the same API call, it would be unclear which value should be saved.

You need to work with the individual fields themselves

Quote myQuote = new Quote();
myQuote.BillingStreet = '123b Baker St.';
myQuote.BillingCity = 'London';
myQuote.BillingState = 'England';
// and so on...

Using the below code helped create a record:

Quote quote = new Quote();
insert quote;

Can you try this

  • What is this SBQQ__ ? I tried it on anonymous window. But shows an error: Invalid type: SBQQ__Quote__c Commented Oct 24, 2020 at 12:19
  • My actual issue is , I need to create the quote object from quote record page. As we know, we can only create the 'Quote' object from related list of 'opportunity'. So I decided to create a custom button in 'Quote' record page. But when quote is inserted, it showing as required field 'OpportunityId' missing, Actually I don't want opportunity. Commented Oct 24, 2020 at 12:23
  • So the billing address details which I have set through an apex code is getting overrided with Opportunity Address values. Is there any solution for this. How can we seperate quote from 'Opportunity'? Commented Oct 24, 2020 at 12:25
  • Sorry I thought the quote was from cpq package but I think the above code should work and as the quotes reside under the opportunity the opportunityid is required and I think it might not be possible to create a record without opportunityid. [the above id of opportunity is one that was present in my org]
    – Anutej
    Commented Oct 24, 2020 at 12:44

You must log in to answer this question.

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