I'd like to create a lead via apex and set it's address. I've read that Address is a compound field and that it is totally read only unless via SOAP/REST API. Looking at the docs, I could only find getter methods - nothing to set a value.

How do I go about setting an address via apex?

Thank you!

2 Answers 2


You set the individual fields, such as BillingStreet, BillingCity, BillingState, BillingPostalCode, and BillingCountry (plus the geolocation codes, as well, if you prefer). The address complex field is a convenience field derived from the parts, just as a contact or lead's "Name" field is really a concatenation of the various parts of their name (first, last, etc).


Here's an example for a new Lead:

Lead lead = new Lead(

                    OwnerId = u.Id,

                    FirstName = 'John',
                    LastName = 'Doe',
                    Email = 'jdoe@congress.gov,
                    Company = 'USA,
                    Title = 'Senator',

                    LeadSource = 'Website',

                    Street = '2100 Woodward Ave',
                    City = 'Detroit',
                    State = 'MI',
                    PostalCode = '48201',
                    Country = 'US',

                    RecordTypeId = recordTypeId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.