# IF_Queryable

**Class** · Group: `Query Infrastructure`

<div class="apex-member apex-class">

```apex
global interface IF_Queryable
```

**Known Derived Types:** [QRY_Builder.Builder](/reference/apex/qry-builder-builder), [SEL_ApiCall](/reference/apex/sel-apicall), [SEL_ApiIssue](/reference/apex/sel-apiissue), [SEL_Base](/reference/apex/sel-base), [SEL_ContentVersion](/reference/apex/sel-contentversion), [SEL_EmailTemplate](/reference/apex/sel-emailtemplate), SEL_Foobar, [SEL_Group](/reference/apex/sel-group), [SEL_OrgWideEmailAddress](/reference/apex/sel-orgwideemailaddress), [SEL_PermissionSet](/reference/apex/sel-permissionset), [SEL_PermissionSetGroup](/reference/apex/sel-permissionsetgroup), [SEL_Profile](/reference/apex/sel-profile), [SEL_User](/reference/apex/sel-user), [SEL_UserRole](/reference/apex/sel-userrole), [QRY_Builder.Builder.count()](/reference/apex/qry-builder-builder#count), [SEL_Base.count()](/reference/apex/sel-base#count), [QRY_Builder.Builder.exists()](/reference/apex/qry-builder-builder#exists), [SEL_Base.exists()](/reference/apex/sel-base#exists), [QRY_Builder.Builder.getFirst()](/reference/apex/qry-builder-builder#getfirst), [SEL_Base.getFirst()](/reference/apex/sel-base#getfirst), [QRY_Builder.Builder.toList()](/reference/apex/qry-builder-builder#tolist), [SEL_Base.toList()](/reference/apex/sel-base#tolist), [QRY_Builder.Builder.toQueryLocator()](/reference/apex/qry-builder-builder#toquerylocator), [SEL_Base.toQueryLocator()](/reference/apex/sel-base#toquerylocator)

Interface for any object that can execute a query. Implemented by QRY_Builder.Builder and SEL_Base. Allows polymorphic query execution across framework components such as batch jobs, async processors, and purge utilities.

**Example**

```apex
public class MyQueryable implements IF_Queryable
{
    public List<SObject> toList() { return query.toList(); }
    public SObject getFirst() { return query.getFirst(); }
    public Database.QueryLocator toQueryLocator() { return query.toQueryLocator(); }
    public Integer count() { return query.count(); }
    public Boolean exists() { return query.exists(); }
}
```

**See Also:** [QRY_Builder](/reference/apex/qry-builder), [SEL_Base](/reference/apex/sel-base)

</div>

---

## Methods

| Method | Description |
|--------|-------------|
| global abstract [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm) [count](#count)() | Returns the count of matching records. |
| global abstract [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) [exists](#exists)() | Returns true if any records match the query. |
| global abstract [SObject](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm) [getFirst](#getfirst)() | Executes the query and returns the first matching record, or null. |
| global abstract [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[SObject](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm)> [toList](#tolist)() | Executes the query and returns all matching records. |
| global abstract [Database.QueryLocator](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_batch.htm) [toQueryLocator](#toquerylocator)() | Returns a QueryLocator for batch processing. |

### count

<div class="apex-member">

```apex
global abstract Integer count()
```

Returns the count of matching records.

**Returns** [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm) — Number of matching records

</div>

### exists

<div class="apex-member">

```apex
global abstract Boolean exists()
```

Returns true if any records match the query.

**Returns** [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) — True if at least one record matches

</div>

### getFirst

<div class="apex-member">

```apex
global abstract SObject getFirst()
```

Executes the query and returns the first matching record, or null.

**Returns** [SObject](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm) — First matching SObject or null

</div>

### toList

<div class="apex-member">

```apex
global abstract List<SObject> toList()
```

Executes the query and returns all matching records.

**Returns** [SObject](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm) — List of matching SObjects

</div>

### toQueryLocator

<div class="apex-member">

```apex
global abstract Database.QueryLocator toQueryLocator()
```

Returns a QueryLocator for batch processing.

**Returns** [Database.QueryLocator](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_database_batch.htm) — QueryLocator for this query

</div>
