Apex Examples

Apex code examples for Custom Address Fields. The examples create a record with custom address data, update the custom address on an existing record, and delete a record that contains custom address data.

Required Editions
Available in: all editions.

Before you create a custom address field, review the Custom Address Fields Requirements and Limitations. To discuss the feature and ask questions, join the Custom Address Fields Discussion group on the Trailblazer Community.

This example code creates an Opportunity record which includes address data stored in the custom address field, “Mailing Address”.

This example code add a record for a custom object, “Gas Station” (Gas_Station__c). The new record includes address data stored in the the custom address field, “Mailing Address”.

This example code updates the custom address field “Mailing Address” on an Opportunity record with ID 006XXXXXXXXXXXXXXX.

This example code updates an existing record for a custom object, “Gas Station” (Gas_Station__c) with ID aIsXXXXXXXXXXXXXXX. It updates custom address field “Mailing Address”.

To delete an address stored in a custom address field from a record, update the record. This example code removes the data stored the custom address field “Mailing Address” on an Opportunity record with ID 006XXXXXXXXXXXXXXX.

This code deletes a record for the custom object, “Gas Station” (Gas_Station__c) with ID aIsXXXXXXXXXXXXXXX. When a record is deleted, all data for that record is deleted, including the custom address field information.