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.


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

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.SnowflakeSchemaResponse response = connection.executeQuery('select * from FINANCIAL_TRANSACTIONS where ACCOUNT_NUMBER=?',queryBindings);
Integer totalRowsInt =;
List<List<String>> rowset =;
List<omnata_sf.SnowflakeSchemaResponse.Rowtype> rowtypes =;
// 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();


The followings exceptions may be thrown by the executeQuery method:
  • ExternalObjectException if Snowflake returns an error message
  • omnata_sf.UnauthorizedException if 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.
omnata_sf.SnowflakeSchemaResponse mockResponse = new omnata_sf.SnowflakeSchemaResponse(); = new omnata_sf.SnowflakeSchemaResponse.Data(); = new List<omnata_sf.SnowflakeSchemaResponse.Rowtype>();
// Add column metadata
omnata_sf.SnowflakeSchemaResponse.Rowtype firstColumn = new omnata_sf.SnowflakeSchemaResponse.Rowtype(); = 'Column1';
firstColumn.type_Z = 'VARCHAR'; // This is the Snowflake column's native data type
firstColumn.scale = 100;;
omnata_sf.SnowflakeSchemaResponse.Rowtype secondColumn = new omnata_sf.SnowflakeSchemaResponse.Rowtype(); = 'Column2';
secondColumn.type_Z = 'FIXED';
firstColumn.scale = 10;
firstColumn.precision = 2;;
omnata_sf.SnowflakeSchemaResponse.Rowtype thirdColumn = new omnata_sf.SnowflakeSchemaResponse.Rowtype(); = 'Column3';
thirdColumn.type_Z = 'BOOLEAN';;
omnata_sf.SnowflakeSchemaResponse.Rowtype fourthColumn = new omnata_sf.SnowflakeSchemaResponse.Rowtype(); = 'Column4';
fourthColumn.type_Z = 'TIMESTAMP_LTZ';;
// add row values, these are always just a 2D matrix of the raw values Snowflake returns
DateTime dt1 = DateTime.newInstanceGmt(2017,4,9,0,0,0);
DateTime dt2 = DateTime.newInstanceGmt(2019,10,9,5,30,15); = new List<List<String>>(); List<String>{'AColumn1Value','123.45','0',(dt1.getTime()/1000)+''}); // Snowflake returns epoch seconds List<String>{'AnotherColumn1Value','456.78','1',(dt2.getTime()/1000)+''});;
// pass in the mock object, instead of a connection name
omnata_sf.SnowflakeConnection connection = new omnata_sf.SnowflakeConnection(mockResponse);
// execute a query to get your own response object back
omnata_sf.SnowflakeSchemaResponse response = connection.executeQuery('doesnt matter what goes here, not sent to Snowflake',null);
Integer totalRowsInt =;
List<List<String>> rowset =;
List<omnata_sf.SnowflakeSchemaResponse.Rowtype> rowtypes =;
// Use this option to get a list of rows, with columns indexed by name
List<Map<String,Object>> allRowsWithNamedColumns = response.getAllRowsWithNamedColumns();
System.debug('Completed successfully');
Copy link
On this page
Querying data from custom Apex code
Example code
Mocking for tests