Newer Version Available

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

REST API Examples

Use REST API to create, update, or delete a record with Custom Address Fields data.

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

Create a New Account with Data in a Custom Address Field

To create a new record, use the sObject resource. You supply the required field values in the request data, and send the request using the POST HTTP method. The response body contains the ID of the new record if the call is successful.

This example creates an Account record which includes address data stored in the Mailing Address custom address field.
Example HTTP POST method to create a new Account
1curl https://MyDomainName.my.salesforce.com/services/data/64.0/sobjects/Account -H "Authorization: Bearer token" -H "Content-Type: application/json" -d "@newaccount.json"
Example request body newaccount.json file to create a new Account
1{
2"Name" : "Acme Incorporated",
3"Mailing_Address__City__s" : "Ahmedabad",
4"Mailing_Address__CountryCode__s" : "IN",
5"Mailing_Address__Street__s" : "102 Suryakoti",
6"Mailing_Address__PostalCode__s" : "380022",
7"Mailing_Address__StateCode__s": "GJ",
8"Mailing_Address__Latitude__s" : "37.775",
9"Mailing_Address__Longitude__s" : "-122.418",
10"Mailing_Address__GeocodeAccuracy__s" : "Address"
11}
Example response body after successfully creating a new Account
1{
2  "id" : "001XXXXXXXXXXXXXXX",
3  "errors" : [ ],
4  "success" : true
5}

Update Data Within a Custom Address Field on a Record

To update a record, use the sObject Rows resource. Provide the updated record information in your request data and use the PATCH method of the resource with a specific record ID to update that record. Records in a single file must be of the same object type.

This example updates the data stored in the Mailing Address custom address field for record ID 001XXXXXXXXXXXXXXX.
HTTP PATCH example for updating an Account
1curl https://MyDomainName.my.salesforce.com/services/data/64.0/sobjects/Account/001XXXXXXXXXXXXXXX -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @patchaccount.json -X PATCH
Example request body patchaccount.json file for updating the custom field, Mailing Address, on an Account
1{
2"Mailing_Address__City__s" : "Surendranagar",
3"Mailing_Address__CountryCode__s" : "IN",
4"Mailing_Address__Street__s" : "20 Udhyog Nagar",
5"Mailing_Address__PostalCode__s" : "363001",
6"Mailing_Address__StateCode__s":  "GJ",
7"Mailing_Address__Latitude__s" : "22.757580",
8"Mailing_Address__Longitude__s" : "71.619350",
9"Mailing_Address__GeocodeAccuracy__s" : "Address"
10}
Example response body after successfully updating an Account
None returned

Delete Data Within a Custom Address Field on a Record

To delete address data stored within a custom address field on a record, update the record with the sObject Rows resource. Provide the updated record information in your request data and use the PATCH method of the resource with a specific record ID to update that record. Records in a single file must be of the same object type.

This example deletes the data stored in the Mailing Address custom address field for record ID 001XXXXXXXXXXXXXXX.
HTTP PATCH example for updating an Account
1curl https://MyDomainName.my.salesforce.com/services/data/64.0/sobjects/Account/001XXXXXXXXXXXXXXX -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @patchaccount.json -X PATCH
Example request body patchaccount.json file for updating the custom field, Mailing Address, on an Account
1{
2"Mailing_Address__City__s" : null,
3"Mailing_Address__CountryCode__s" : null,
4"Mailing_Address__Street__s" : null,
5"Mailing_Address__PostalCode__s" : null,
6"Mailing_Address__StateCode__s":  null,
7"Mailing_Address__Latitude__s" : null,
8"Mailing_Address__Longitude__s" : null,
9"Mailing_Address__GeocodeAccuracy__s" : null
10}
Example response body after successfully updating an Account
None returned

Delete a Record That Contains Data in a Custom Address Field

To delete records, use the sObject Rows resource. Specify the record ID and use the DELETE method of the resource to delete a record. When a record is deleted, all data for that record is deleted, including the custom address field information.

This example deletes the Account record with ID 001XXXXXXXXXXXXXXX.

HTTP DELETE example for updating an Account
1curl https://MyDomainName.my.salesforce.com/services/data/64.0/sobjects/Account/001XXXXXXXXXXXXXXX  -H "Authorization: Bearer token" -X DELETE
Example request body
None needed
Example response body after successfully updating an Account
200 OK