Newer Version Available

This content describes an older version of this product. View Latest

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.
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.

Note

Insert a Record

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”.

Update an Existing Record

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”.

Delete Data Within a Custom Address Field from a Record

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.

Delete a Record

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.