SEL_ApiIssue
Class · Group: Web Services
Learn it: Fast Start - Selectors and Selectors guide
global inherited sharing class SEL_ApiIssue extends SEL_BaseExtends: SEL_Base
Selector for the ApiIssue__c SObject. Provides query methods for retrieving and filtering failed API calls, including deduplication via request parameter hash and status-based filtering.
Example
List<ApiIssue__c> issues = new SEL_ApiIssue().findUnresolvedByService('API_SendEmail');
List<ApiIssue__c> inbound = new SEL_ApiIssue().findUnresolvedInbound();
ApiIssue__c issue = (ApiIssue__c)new SEL_ApiIssue().findById(issueId);See Also: SEL_Base, SEL_ApiCall
Methods
| Method | Description |
|---|---|
| global List<ApiIssue__c> findByFailedApiCall(Id recordId, String serviceName, String hashParameter) | Finds every user's open issues for one request: the same triggering record, service name and request parameters hash. |
| global List<ApiIssue__c> findByTriggeringRecordIds(Set<Id> recordIds, Integer rowLimit) | Finds the issues raised for calls made for the given records, newest first, and returns at most rowLimit of them. |
| global List<ApiIssue__c> findByTriggeringRecordValues(Set<String> values, Integer rowLimit) | Finds the issues with one of the given values in Triggering Record Index (TriggeringRecordIndex__c), newest first, and returns at most rowLimit of them. |
| global List<ApiIssue__c> getAll() | Retrieves all ApiIssue__c records. |
| global override List<SObjectField> getFields() | Returns the core fields for ApiIssue__c queries. |
findByFailedApiCall
global List<ApiIssue__c> findByFailedApiCall(Id recordId, String serviceName, String hashParameter)Finds every user's open issues for one request: the same triggering record, service name and request parameters hash. Use it to find out whether a request you know about has failed and is still open, for example to mark those issues resolved once the request succeeds.
The method reads in system mode and ignores record sharing, so it returns the open issues of every user, not only the ones the running user owns or can see. That is safe because you must already hold the record Id, the service name and the request parameters hash to ask: you are asking about a request you know. The framework itself relies on this answer when a later call for the same request succeeds, and the user whose call succeeds is often not the user whose call failed. Your code decides what to show to whom: if you show the returned issues to a person, check that they may see them first.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | Id | The Id of the triggering record |
serviceName | String | The name of the web service |
hashParameter | String | The request parameters hash to match |
Returns ApiIssue__c — The open issues for the request, whoever owns them
findByTriggeringRecordIds
global List<ApiIssue__c> findByTriggeringRecordIds(Set<Id> recordIds, Integer rowLimit)Finds the issues raised for calls made for the given records, newest first, and returns at most rowLimit of them. Issues saved at the same moment are ordered by their own Id, newest first, so the order is the same every time.
An issue is found by its Triggering Record Index field (TriggeringRecordIndex__c), which holds the record Id exactly as it was written on the issue. This method finds values stored in the full form of 18 characters, which is the form the framework writes. It does not find a value stored in the short form of 15 characters. Code that sets the Triggering Record Id field (TriggeringRecordId__c) itself should write the full form, for example String.valueOf(recordId).
Each issue holds only these fields: Id, ServiceName__c, Status__c, CreatedDate and TriggeringRecordIndex__c. To get the request of an issue, read that issue by its Id.
Triggering Record Index is filled each time an issue is saved. An issue saved before the field existed has it blank until the update script in the release notes is run, and this method does not find it.
The read checks the running user's access. The user needs read access to the API Issue object and to each field above, and gets only the issues that record sharing lets them see. A user without that object or field access gets an error (a QueryException) instead of a result.
In a test, the mocked issues are filtered the way the query filters saved ones: only those whose Triggering Record Index holds one of the values come back. A mock is never saved, so Triggering Record Index is not filled for it: set it on the mock yourself, because a mock that sets only Triggering Record Id is not found. The match in a test is exact, so a value in another case is not found. An answer scripted with TST_Mock.registerNext is filtered the same way, so give its mocks the values this method searches for.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordIds | Set | The Ids of the records the failed calls were made for. A null Id in the set is ignored. The set you pass is not changed. |
rowLimit | Id | The most issues to return: 1 or more. |
Returns ApiIssue__c — The issues found, newest first. An empty list when the set holds no Id; then no query is run.
Throws
| Exception | Description |
|---|---|
| IllegalArgumentException | When recordIds is null, or rowLimit is null or less than 1. |
Example
List<ApiIssue__c> issues = new SEL_ApiIssue().findByTriggeringRecordIds(new Set<Id> {accountId}, 10);findByTriggeringRecordValues
global List<ApiIssue__c> findByTriggeringRecordValues(Set<String> values, Integer rowLimit)Finds the issues with one of the given values in Triggering Record Index (TriggeringRecordIndex__c), newest first, and returns at most rowLimit of them. Issues saved at the same moment are ordered by their own Id, newest first, so the order is the same every time. Use it when the failed calls were made for something that is not a record in this org, such as an order number from another system; for record Ids, findByTriggeringRecordIds is simpler.
Such a value can come from an inbound call, from an issue your own code saves, or from an outbound call whose class sets requiresTriggeringRecord to false. An issue keeps the whole value of the call that failed, up to 80 characters.
Triggering Record Index holds the Triggering Record Id field (TriggeringRecordId__c) exactly as it was written on the issue. Each value is matched as you write it, but the match ignores upper and lower case: 'ORD-1' also finds an issue whose Triggering Record Index is 'ord-1'. Do not use this method for record Ids in the short form of 15 characters: the short forms of two different records can differ only by case, so it could return issues raised for another record.
Each issue holds only these fields: Id, ServiceName__c, Status__c, CreatedDate and TriggeringRecordIndex__c. To get the request of an issue, read that issue by its Id.
Triggering Record Index is filled each time an issue is saved. An issue saved before the field existed has it blank until the update script in the release notes is run, and this method does not find it.
The read checks the running user's access. The user needs read access to the API Issue object and to each field above, and gets only the issues that record sharing lets them see. A user without that object or field access gets an error (a QueryException) instead of a result.
In a test, the mocked issues are filtered the way the query filters saved ones: only those whose Triggering Record Index holds one of the values come back. A mock is never saved, so Triggering Record Index is not filled for it: set it on the mock yourself, because a mock that sets only Triggering Record Id is not found. The match in a test is exact, so a value in another case is not found. An answer scripted with TST_Mock.registerNext is filtered the same way, so give its mocks the values this method searches for.
Parameters
| Parameter | Type | Description |
|---|---|---|
values | Set | The values to look for. A null or blank value in the set is ignored. The set you pass is not changed. |
rowLimit | String | The most issues to return: 1 or more. |
Returns ApiIssue__c — The issues found, newest first. An empty list when the set holds no value; then no query is run.
Throws
| Exception | Description |
|---|---|
| IllegalArgumentException | When values is null, or rowLimit is null or less than 1. |
Example
List<ApiIssue__c> issues = new SEL_ApiIssue().findByTriggeringRecordValues(new Set<String> {'ORD-99182'}, 10);getAll
global List<ApiIssue__c> getAll()Retrieves all ApiIssue__c records. Only executes in test context to prevent full-table scans in production.
Returns ApiIssue__c — List of all ApiIssue__c records in test context, empty list in production
Example
List<ApiIssue__c> result = instance.getAll();getFields
global override List<SObjectField> getFields()Returns the core fields for ApiIssue__c queries.
Returns SObjectField — List of ApiIssue__c SObjectField tokens
Example
List<SObjectField> result = instance.getFields();Constructors
| Constructor | Description |
|---|---|
| global SEL_ApiIssue() | Reads ApiIssue__c records: the issues raised for failed web service calls. |
SEL_ApiIssue()
global SEL_ApiIssue()Reads ApiIssue__c records: the issues raised for failed web service calls. Its queries skip the running user's object and field permission checks (system mode), except the two finders by triggering record, findByTriggeringRecordIds and findByTriggeringRecordValues. Those two run in user mode, so they respect the running user's object access, field access and record sharing. For the other queries, record sharing follows the class that calls the selector, unless a method says otherwise. Creating the selector runs no query.
Example
SEL_ApiIssue instance = new SEL_ApiIssue();