Omnata with Salesforce Apex
Querying data from custom Apex code
Omnata provides a native Apex interfaces to your data warehouse. This allows a Salesforce developer to query external data as needed, without needing to build and maintain a custom API integration, or handle the various data type conversions.
Only Snowflake is supported.
The Apex interface is closer to the wire than Salesforce Connect, so different product APIs return different classes.
Prerequisites
Ensure that package installation and initial connection configuration has been performed.
Once complete, data can be queried via custom Apex code by referencing the connection by name.
Example code (New Snowflake API)
omnata_sf.SnowflakeConnection connection = new omnata_sf.SnowflakeConnection('Snowflake');
List<omnata_sf.SnowflakeQueryBinding> queryBindings = new List<omnata_sf.SnowflakeQueryBinding>();
String testString = 'A000001';
queryBindings.add(new omnata_sf.SnowflakeQueryBinding(testString));
omnata_sf.SnowflakeApiQueryResponse response = connection.executeQueryV2('select * from FINANCIAL_TRANSACTIONS where ACCOUNT_NUMBER=?',queryBindings);
Integer totalRows = response.resultSetMetaData.numRows;
List<List<String>> rowset = response.data;
List<omnata_sf.SnowflakeApiQueryResponse.Rowtype> rowtypes = response.resultSetMetaData.rowtype;
// If you don't need type conversion, this is the string representation straight from Snowflake
List<String> firstRow = rowset.get(0);
String firstColumnValueOfFirstRow = firstRow.get(0);
// Use this option to get a list of rows, with columns indexed by name
List<Map<String,Object>> allRowsWithNamedColumns = response.getAllRowsWithNamedColumns();
// Use this option to get a list of rows, with columns indexed by position
List<List<Object>> allRowsWithOrdinalColumns = response.getAllRowsWithOrdinalPositions();
Example code (Old Snowflake API)
Exceptions
The followings exceptions may be thrown by the executeQuery method:
ExternalObjectExceptionif Snowflake returns an error messageomnata_sf.UnauthorizedExceptionif the connection fails due to invalid credentials.
Mocking for tests
The containers that carry API responses are global classes, so that they can be mocked.
Below is an example Apex script where the response to a simple Snowflake query is mocked.
New Snowflake API
Old Snowflake API
Last updated