---
schema_version: "1"
id: 7e04184945de5fb8e96547c9ae6b38ebbdca5113ddedfe0e40141471ee9a8413
title: Interface DataApi
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-functions/functions/guide/javasdk/interfaces/java-dataapi.md
canonical_url: https://developer.salesforce.com/docs/platform/functions/guide/java-dataapi.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c3fc0e11f4ef0d5bc902a55d3952f3b3f09c9ca44e965a84a46484ceeb2ef6ac
products:
  - Salesforce Functions
---
# Interface DataApi

------------------------------------------------------------------------

public interface DataApi

Data API client to interact with data in a Salesforce org.

## Method Summary

| Modifier and Type                                      | Method                                                                | Description                                                          |
| ------------------------------------------------------ | --------------------------------------------------------------------- | -------------------------------------------------------------------- |
| `java.util.Map<ReferenceId, RecordModificationResult>` | `commitUnitOfWork(UnitOfWork unitOfWork)`                             | Commits a `UnitOfWork`, executing all operations registered with it. |
| `RecordModificationResult`                             | `create(Record record)`                                         | Creates a new record of the given type with the given fields          |
| `RecordModificationResult`                             | `delete(java.lang.String type, java.lang.String id)`                                         | Deletes an existing record of the given type and id.          |
| `java.lang.String`                                     | `getAccessToken()`                                                    | Returns the access token used by this API client.                    |
| `RecordBuilder`                                         | `newRecordBuilder(java.lang.String type)`                              | Creates a new and empty RecordBuilder that can be used to build a `Record` object for use with the `update(Record)` and `create(Record)` methods.             |
| `RecordBuilder`                                         | `newRecordBuilder(Record record)`                              | Creates a new RecordBuilder, pre-initialized from the given `Record`. The type and all fields present in that Record will be set on the returned RecordBuilder.             |
| `UnitOfWorkBuilder`                                         | `newUnitOfWorkBuilder()`                                  | Creates a new and empty UnitOfWorkBuilder that can be used to build a `UnitOfWork` object for the `commitUnitOfWork(UnitOfWork)` method. |
| `RecordQueryResult`                                    | `query(java.lang.String soql)`                                        | Queries for records with a given SOQL string.                        |
| `RecordQueryResult`                                    | `queryMore(RecordQueryResult queryResult)`                            | Queries for more records, based on the given `RecordQueryResult`.    |
| `RecordModificationResult`                             | `update(Record record)`                                         | Updates an existing record of the given type and id with the given fields.    |

## Method Details

### query

\@Nonnull RecordQueryResult query​(java.lang.String soql) throws
DataApiException

Queries for records with a given SOQL string.

Parameters: `soql` - The SOQL string. Returns: a `RecordQueryResult`
that contains the queried data. Throws: `DataApiException` - If error
occurred during the query. See Also: Salesforce Object Query Language
(SOQL)

### queryMore

\@Nonnull RecordQueryResult queryMore​(RecordQueryResult queryResult)
throws DataApiException

Queries for more records, based on the given `RecordQueryResult`.

Parameters: `queryResult` - The query result to query more data for.
Returns: A new `RecordQueryResult` with additional data or an empty one
if the given RecordQueryResult was already in the done state. Throws:
`DataApiException` - If error occurred during the query.
`java.lang.IllegalArgumentException` - If the `RecordQueryResult`
instance wasn\'t created by this `DataApi` instance. See Also:
`RecordQueryResult.isDone()`

### create

\@Nonnull RecordModificationResult create​(Record record) throws
DataApiException

Creates a new record of the given type with the given fields.

Parameters: `record` - The record to create. Returns: A
`RecordModificationResult` for this operation. Throws:
`DataApiException` - If an API error occurred during record creation.
`java.lang.IllegalArgumentException` - If the `Record` instance wasn\'t
created by a `RecordBuilder` obtained from this `DataApi` instance.

### update

\@Nonnull RecordModificationResult update​(Record record) throws
DataApiException

Updates an existing record of the given type and id with the given
fields.

Parameters: `record` - The record to update. Returns: A
`RecordModificationResult` for this operation. Throws:
`DataApiException` - If an API error occurred during record update.
`java.lang.IllegalArgumentException` - If the `Record` instance wasn\'t
created by a `RecordBuilder` obtained from this `DataApi` instance.

### delete

\@Nonnull RecordModificationResult delete​(java.lang.String type,
java.lang.String id) throws DataApiException

Deletes an existing record of the given type and id.

Parameters: `type` - The object type of the record to delete. `id` - The
id of the record to delete. Returns: A `RecordModificationResult` for
this operation. Throws: `DataApiException` - If an API error occurred
during record deletion.

### newRecordBuilder

\@Nonnull RecordBuilder newRecordBuilder​(java.lang.String type)

Creates a new and empty RecordBuilder that can be used to build a
`Record` object for use with the `update(Record)` and `create(Record)`
methods.

Parameters: `type` - The type of the record to build. Returns: A new and
empty RecordBuilder.

### newRecordBuilder

\@Nonnull RecordBuilder newRecordBuilder​(Record record)

Creates a new RecordBuilder, pre-initialized from the given `Record`.
The type and all fields present in that Record will be set on the
returned RecordBuilder.

Parameters: `record` - The `Record` to copy the type and fields from.
Returns: A new RecordBuilder, pre-initialized from the given `Record`.
Throws: `java.lang.IllegalArgumentException` - If the `Record` instance
wasn\'t created by a `RecordBuilder` obtained from this `DataApi`
instance.

### newUnitOfWorkBuilder

\@Nonnull UnitOfWorkBuilder newUnitOfWorkBuilder()

Creates a new and empty UnitOfWorkBuilder that can be used to build a
`UnitOfWork` object for the `commitUnitOfWork(UnitOfWork)` method.

Returns: A new and empty FieldsBuilder.

### commitUnitOfWork

\@Nonnull
java.util.Map\<ReferenceId,​RecordModificationResult\> commitUnitOfWork​(UnitOfWork unitOfWork)
throws DataApiException

Commits a `UnitOfWork`, executing all operations registered with it. If
any of these operations fail, the whole unit is rolled back. To examine
results for a single operation, inspect the returned map (which is keyed
with `ReferenceId` returned from
`UnitOfWorkBuilder.registerCreate(Record)`,
`UnitOfWorkBuilder.registerUpdate(Record)`, and
`UnitOfWorkBuilder.registerDelete(String, String)`.

Parameters: `unitOfWork` - The `UnitOfWork` to commit. Returns: A map of
`RecordModificationResult`s, indexed by their `ReferenceId`s. Throws:
`DataApiException` - If an error occurred while committing the
UnitOfWork. `java.lang.IllegalArgumentException` - If the `UnitOfWork`
instance wasn\'t created by a `UnitOfWorkBuilder` obtained from this
`DataApi` instance. See Also: `newUnitOfWorkBuilder()`

### getAccessToken

\@Nonnull java.lang.String getAccessToken()

Returns the access token used by this API client. Can be used to
initialize a third-party API client or to perform custom API calls with
a HTTP library.

Returns: the access token used by this API client.
